font: normal 11px Verdana, Arial, Helvetica, sans-serif;
padding: 0px 0px 5px 0px;
The HTML markup is listed below:
<a href="#" class="menu">
<span class="navbar">Products</span><br />
Stereo Editors<br />
Multitrack Editors<br />
That's all of the necessary code to make our simple menu work. Let's explain our CSS declarations:
We've defined a class "navbar" which will be displayed initially as the navigation element for our menu. As usual, we've styled the element using fonts, background colors, padding and the like. The only property to be noticed is "display: block." Since this element will be included within an <a> element, we need it to behave as a block-level element.
Next, we've declared another class "menu," which acts as the menu for the navigation bar element. Here, we're taking advantage of each state for the "a:link" and "a:hover" pseudoclasses. Since our menu is built around the <a> element, we need to initially hide the menu items. That's what we do by setting a height of 18px and assigning the property "overflow: hidden" for the "a:link" state. This way, all of the menu items will be properly hidden since they exceed height.
Then, for the a:hover state, we just assign a new width of 90px for menu items and set the overflow property to "visible." This causes the menu items to be displayed when the mouse it's hovered on the link. Quite simple, isn't it?
The output for this simple drop-down menu is illustrated is the following sequence:
In this article, we've looked closely at the most common CSS2 visual properties, which are strongly oriented to position elements in Web documents. Also, with the help of numerous examples, we were able to implement those properties in order to make them work for us in an efficient way. As usual with client-side techniques, we should always be aware of browser support. However, since old fourth-generation browsers are progressively being replaced by today's versions, we can take advantages of the benefits and capabilities available from using the newer CSS2 specifications.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.