HTML for a Common Browser Menu - More on the Elements and Attributes
(Page 2 of 4 )
The DIV element has an ID and the style attribute. We shall talk about the use of the ID later. The first property in the style attribute is the position property. The value of the position property is "absolute." When you give the "absolute" value to the position property of an element and you do not give the element the CSS left and top properties, the element will remain in the position of the normal flow.
However, under this condition, the element will appear in front the other elements in the normal flow, beginning from the position where it was put. An element will appear in front of another depending on the z-indices of the two elements. The one with the higher z-index appears in front. The BODY element behaves as if it has a z-index of zero. Elements in the normal flow behave as if they have a z-index of 1. So I gave the DIV element a z-index of 10 to make sure it appears in front of the elements around it. It would hardly ever happen that any element in your web page would have a z-index of up to 10.
The background of the DIV is transparent. The value of the display property is "block." Since the z-index value is 10, the DIV appears in front of all the elements behind it. When any sub menu item has to be displayed, the background of its cell is given a color. So you do not see through the DIV where table cells have background color, but you see through the DIV where there is no cell background color. For simplicity and compatibility between browsers, the border-width of the DIV is zero, the padding is zero and the margin is zero. Note that different browsers may have different default values for these three properties.
The table inside the DIV element has a cellpadding of zero, a cellspacing of zero and border of zero. The widths of the columns of the table in the DIV are the same as the widths of the columns of the table in the main menu. This is done by CSS.
With all these specifications, the corresponding columns between the table in the main menu and the table in the DIV are aligned. So when you click the Drop Down button, the sub vertical menu you see appears directly below the corresponding link in the main menu.
Do not forget to give a width (value) for the DIV element; otherwise the code will not work with the three browsers that I have mentioned.
Next: The Table Cell Contents in the DIV >>
More HTML Articles
More By Chrysanthus Forcha