CSS Hover Effect with Flyout Menu

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

Continuing from the last tutorial, we now create a CSS hover effect so that a flyout menu appears when menu item is hovered over as demo here.  It looks like this …

flyout menu from CSS hover

flyout menu from CSS hover

We will add the flyout menu to the second menu item as shown …

flyout menu code

flyout menu code

We just added another “ul” element within the existing li element right after the “a” link element.

We now have unstyled flyout menu looking like …

adding flyout menu

adding flyout menu

We need to add the following to our style sheet (style.css in the same folder as our index.html) …

flyout menu styling

flyout menu styling

Our flyout menu ul is nested within our li.  We created a rule for that and position our nested ul as “absolute”.  In order for position absolute to work, the li that is containing it should be set position relative as we done above.   We you position the ul as absolute, set it top and left properties to tell it how to position.

This is how it looks now when positioned …

flyout menu position absolute

flyout menu position absolute

We just need to remove the bullets, give the flyout ul a width and border, and remove margin/padding …

more flyout styling

more flyout styling

The flyout menu looks good, but stuck positioned in place as fixed…

flyout menu placed

flyout menu placed

The css hover effect on the flyout menu itself already works from the previous code.

But we need to apply CSS to not display this flyout menu. And to display it only when the primary menu items are hovered over …

css code for hover menu

css code for hover menu

The display none on the nested ul will hide.  And the display block on the li:hover will show.