To create a vertical navigation bar using CSS, we can use the following steps:
- Create an HTML unordered list (
<ul>
) to hold the navigation links. - Apply a class or ID to the
<ul>
element to target it in CSS. - Set the
display
property of the<ul>
element toinline-block
to make it a block-level element that can have a width and height. - Set the
list-style-type
property tonone
to remove the bullet points. - Set the
padding
property to create some space between the list items and the edges of the<ul>
element. - Apply a background color and font styles to the list items (
<li>
elements). - Set the
width
property of the<li>
elements to make them display vertically. - Add styles to the
a
tags inside the list items to control their appearance.
Here’s an example CSS code for a basic vertical navigation bar:
ul {
display: inline-block;
list-style-type: none;
padding: 0;
margin: 0;
background-color: #f1f1f1;
width: 200px;
}
li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
li a:hover {
background-color: #555;
color: #fff;
}
And here’s an example HTML code for a basic vertical navigation bar:
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
This will create a vertical navigation bar with a light gray background color, black text, and white text on hover. You can customize the CSS code to change the colors, font styles, and other properties to match your desired design.