To build a vertical navigation bar, you can style the elements inside the list, in addition to the code from the previous page:
display: block;
– Displaying the links as block elements makes the whole link area clickable (not just the text), and it allows us to specify the width (and padding, margin, height, etc. if you want).
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.
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:
Add an "active" class to the current link to let the user know which page he/she is on:
Add text-align: center;
to <li>
or <a>
to center the links.
Add the border
property to <ul>
to add a border around the navbar. If you also want borders inside the navbar, add a border-bottom
to all <li>
elements, except for the last one.