Slide 5.27: CSS navigation bar
Slide 5.29: CSS image gallery
Home

CSS Navigation Bar (Cont.)


Horizontal Navigation Bar
There are two ways to create a horizontal navigation bar—inline or floating list items. Both methods work fine, but if you want the links to be the same size, you have to use the floating method.
Inline list items
One way to build a horizontal navigation bar is to specify the <li> elements as inline by using display:inline;. By default, <li> elements are block elements. Here, we remove the line breaks before and after each list item, to display them on one line.

     


Floating list items
In the example above the links have different widths. For all the links to have an equal width, float the <li> elements and specify a width for the <a> elements:
 li { float:left; }
 a {
  display:block;
  width:100px; }

  • float:left—Gets block elements to slide next to each other.

  • display:block—Displays the links as block elements makes the whole link area clickable (not just the text).

  • width:100px—Specifies the width of the links to 100px.

Demonstration
The following demonstration shows how the script of HTML and CSS is displayed on the Web: