Step 9
Information comes from W3Schools.com
see https://www.w3schools.com/css/css_navbar.asp
CSS Navigation Bar
Navigation Bars
Having easy-to-use navigation is important for any web site.
With CSS you can transform boring HTML menus into good-looking navigation bars.
Navigation Bar = List of Links
A navigation bar uses standard HTML as a base.
In our examples we will build the navigation bar from a standard HTML list.
A navigation bar is basically a list of links, so using the <ul> and <li> elements makes perfect sense:
Example
<ul>
<li><a href="news.asp">News</a></li>
<li><a href="contact.asp">Contact</a></li>
<li><a href="about.asp">About</a></li>
Now let's remove the bullets and the margins and padding from the list: Example ul {
margin: 0;
padding: 0;
Example explained:
Set margin: 0; and padding: 0; to remove browser default settings
The code in the example above is the standard code used in both vertical, and horizontal navigation bars.
Vertical Navigation Bar
To build a vertical navigation bar, you can style the <a> elements inside the list, in addition to the code above:
Example
li a {
Example explained:
width: 60px; - Block elements take up the full width available by default. We want to specify a 60 pixels width
You can also set the width of <ul>, and remove the width of <a>, as they will take up the full width available when displayed as block elements. This will produce the same result as our previous example:
Example
ul {
li a {
Vertical Navigation Bar Examples
Create a basic vertical navigation bar with a gray background color and change the background color of the links when the user moves the mouse over them:
Example
ul {
margin: 0;
padding: 0;
width: 200px;
background-color: #f1f1f1;
li a {
color: #000;
padding: 8px 16px;
text-decoration: none;
/* Change the link color on hover */
li a:hover {
color: white;