To construct a vertical navigation bar, customize the styling of the <a> elements within the list, along with incorporating the code from the preceding page.
Example
li a { display: block; width: 60px; } |
Explanation of the example:
You can also specify the width of `<ul>` and remove the width from `<a>`, as they will automatically occupy the entire available width when displayed as block elements. This adjustment will yield the same outcome as our previous example.
Example
ul { |
Construct a simple vertical navigation bar featuring a gray background, and alter the background color of the links upon mouse hover.
Example
ul { |
Apply an “active” class to the current link to indicate to the user which page they are currently on.
Example
.active { |
Include text-align:center to center-align the links within either <li> or <a>.
Apply the border property to <ul> to create a border around the navigation bar. If borders are desired inside the navbar, add a border-bottom to all <li> elements except the last one.
Example
ul { border: 1px solid #555; } li { text-align: center; border-bottom: 1px solid #555; } li:last-child { border-bottom: none; } |
Create a full-height, “sticky” side navigation:
Example
ul { |
Please be aware that this example may not function correctly on mobile devices.