Requirements for Horizontal CSS Menus
Grab HTML From Here
#menu {The above sets the width onto the individual lists,
width: 100%;
background: #eee;
float: left;
}
#menu ul {
list-style: none;
margin: 0;
padding: 0;
width: 12em;
float: left;
}
<ul>
's, this time as the need to float side by side to make them fit into whatever horizontal space is available to them. This horizontal width is determined by setting the width of the #menu div
itself. The #menu div
is also floated in order to "contain" it's floated descendants.Then we apply the required formatting to the <h2>
headings and the <a>
anchors, again I'm using the same formatting as the vertical menu#menu a, #menu h2 {
font: bold 11px/16px arial, helvetica, sans-serif;
display: block;
border-width: 1px;
border-style: solid;
border-color: #ccc #888 #555 #bbb;
margin: 0;
padding: 2px 3px;
}
#menu h2 {
color: #fff;
background: #000;
text-transform: uppercase;
}
#menu a {
color: #000;
background: #efefef;
text-decoration: none;
}
#menu a:hover {
color: #a00;
background: #fff;
}
Color to taste.
Positioning the Popout Menus and Dropdown Menus#menu li {position: relative;}
#menu ul ul {
position: absolute;
z-index: 500;
}
#menu ul ul ul {
top: 0;
left: 100%;
}
The position: relative; on the <li>
elements establish containing blocks for the descendant <ul>
elements.
Hiding and Revealing using :hover
This time we actually do want to hide the second level menu (top choice) as we only want the <h2>
heading, inside the top level <ul>
to remain visible.div#menu ul ul,The
div#menu ul li:hover ul ul,
div#menu ul ul li:hover ul ul
{display: none;}
div#menu ul li:hover ul,
div#menu ul ul li:hover ul,
div#menu ul ul ul li:hover ul
{display: block;}
display: block;
rules show the three levels being activated with the display: none;
rules being entered afterwards to more specifically hide the unwanted (deeper nested) lists (counteract them).Fix it for IE!
The complete conditional CSS is the same as the vertical menu's code and looks like this:<!--[if IE]><style type="text/css" media="screen">
body {
behavior: url(csshover.htc);
font-size: 100%;
}
#menu ul li {float: left; width: 100%;}
#menu ul li a {height: 1%;}
#menu a, #menu h2 {
font: bold 0.7em/1.4em arial, helvetica, sans-serif;
}
</style>
<![endif]-->