I have built a persistent dropline menu with two levels using only CSS. It is pretty standard.
It is a nested set of UL’s and the UL’s :hover state is what shows and hides the sub menu levels.
Something like this:
| *Pets* | Colors | Cars |
| Cats | Dogs | Birds| Goats | Sheep |
| Pets | *Colors* | Cars |
| Red | Orange | Green | Blue| Yellow |
I then added a 1px border at the bottom of the first level UL element. Like this:
| *Pets* | Colors | Cars |
--------------------------------------
| Cats | Dogs | Birds| Goats | Sheep |
When I hover over a first level item (Pets), and then move the mouse down to the second level (Cats), the entire second level disappears.
I finally figured out that the UL’s 1px border is not included in the hover area for the UL.
Can I add a border to the bottom of a dropline menu level without messing up the menu hovering?
Thanks!
Since you’re actually adding the
:hoverstate to the<li>s within the<ul>, the border on the parent<ul>isn’t included in the:hoverarea. It would solve your problem to add the border to each<li>instead of the parent<ul>. Make sure to add left and right margins of 0 to the<li>s and even if you do that you still might need to add a negative left margin or left position to remove any gaps in the border, as well as add override styles to the submenu<li>s if they end up with a bottom border as well.EDIT: Ok, I’ve got a solution that will hopefully work for you, using the following HTML:
and this CSS:
The key parts here are:
ulto be smaller than the height of the mainul liby an amount equal to theborder-widthdisplay:inline-blockonliso height attribute takes effectzoom:1; _display:inline;for IE6)position:relativeon the mainul liandposition:absoluteon the sub ‘ul li ul’ with ‘top’ value of the main ‘ul li’ heightTested and working: http://jsfiddle.net/TKrSM/1/
(may have to adjust height and top values for padding in your version)