The second round of modifications to the menu_style.css style sheet in this example involves making each list of navigation links into drop-down menus. First a display: none; declaration is supplied to the ul.menu selector to hide all the menus. The display: none; declaration prevents the browser from rendering the menu <ul> elements. Then, the :hover pseudo-class is applied to make those menus reappear if the user’s mouse cursor hovers over a navigational heading:
div#nav > div > ul > li:hover > ul.menu,
ul.menu:hover {
display: block;
}
The first selector in this example works using the same direct child relationship that you’ve observed before. Essentially what you are stating here is the following: If the nav <div> element has a child <div> element, and that child <div> element has a <ul> child element, and that child <ul> element has a <li> element that the user’s mouse is hovering over, and that <li> element has a <ul> element with a menu class name, display it as a block element. This creates the effect of dynamic drop-down menus using CSS. The second selector is applied merely as a logical precaution. If the user’s mouse is hovering over a <ul> element with a menu class name, for example any submenu, you continue to display that element as a block element.
Hi! My name is Warren Brown. I'm a professional computer marketer with an Engineering degree from Caltech. My other job is being a journalist for Maximum PC magazine where I publish my tests and reviews of various IT stuff. This blog is a place where I express my views on both modern technologies and specific computers, mobiles, etc.