Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Web Design ›
How to create a horizontal drop down menu in CSS

How to create a horizontal drop down menu in CSS

November 2, 2011 Web Design Jesin A Leave a Comment

web design category thumbnail

Its been a long time since I wrote an article in this category (Web Design) so I decided to write an article on creating a horizontal drop down menu purely with HTML and CSS. To create a simple menu see CSS Horizontal Navigation Menu. Since the horizontal drop down menu uses only CSS and HTML it doesn’t work with Internet Explorer 6. The whole drop down menu concept makes use of the CSS pseudo class :hover, when you place the mouse pointer over a parent menu the CSS “display” attribute changes to “block” and displays the drop down menu, when you move the mouse pointer away from the menu the “display” attribute changes to “none” so the drop down menu disappears.

Here is the entire code for a horizontal drop down menu

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>CSS Menu</title>
<style type="text/css">
ul#navbar {
list-style-type: none;
margin: 0;
padding: 0;
}
ul#navbar li {
float: left;
border: 1px solid black;
text-align: center;
}
ul#navbar a {
background-color: #CCC;
color: #000;
text-decoration: none;
display: block;
width: 120px;
padding: 4px;
}
ul#navbar a:hover {
background-color: #CFF;
text-decoration: underline;
}
ul#navbar ul {
display: none;
list-style-type: none;
}
ul#navbar li:hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0;
}
ul#navbar li:hover li {
float: none;
}
</style>
</head>
<body>
<ul id="navbar">
<li><a href="#">Home</a></li>
<li><a href="#">Parent 1</a>
<ul>
<li><a href="#">Child 1</a></li>
<li><a href="#">Child 2</a></li>
<li><a href="#">Child 3</a></li>
</ul></li>
<li><a href="#">Parent 2</a>
<ul>
<li><a href="#">Child 1</a></li>
<li><a href="#">Child 2</a></li>
<li><a href="#">Child 3</a></li>
</ul></li>
</ul>
</body>
</html>

Notice the DOCTYPE declaration at the beginning, without this the code will not work in Internet Explorer. See a live demo

CSS Horizontal drop down menu DEMO

Related posts:

web design category thumbnailCSS Horizontal Navigation Menu web design category thumbnailCSS Tableless Design Tutorial Default ThumbnailHow to create custom error page in Apache linux category thumbnailHow to create a swap file in Linux jquery add remove textboxHow to Add/Remove text boxes using jQuery and PHP

Tags: css, html

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.