This is an easy Navigation bar with no so many functions. When you hover on one item, the background change and all the items are able to click. And here is a preview of the navigation bar.
The content is simple, and it’s displayed in a row in browser. If we want to get the format, we need to give styles to the content.
*
1 2 3 4
* { margin: 0; padding: 0; }
We use this to erase the original style given by the browser.
#nave
1 2 3 4 5 6 7 8 9 10 11 12
#nav { /* clear the circle shape before list */ list-style: none; /* set a background color for the ul */ background-color: skyblue; /* In IE6, if you set a width to it, then it's height won't crash */ width: 1000px; /* use auto to make it display in the center of browser */ margin: 50px auto; /* solve for the height crash problem */ overflow: hidden; }
#nav li
1 2 3 4 5 6
#navli { /* let the item display in one line */ float: left; /* set the width for each item, since we have four items, width is 1/4 */ width: 25%; }
If we want the hole area clickable, we need to set width to <a>. However, since we use float, <a> is disengaged in document flow so its parent has no width. So we need to set the the width to li and make width of <a> 100%.
#nav a
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#nava { /* make it not inline item */ display: block; /* its parent is li which we already set the width*/ width: 100%; /* display in the center */ text-align: center; /* set height of the bar */ padding: 5px0px; /* get rid of the underline */ text-decoration: none; color: white; font-weight: bold; }
#nav a:hover
When the mouse is over, the block changed into a different color. We use Pseudo class.