CSS Navigation Bar
A navigation bar is a list of links that allows users to navigate a website. CSS can be used to style and customize the navigation bar to match the design of the website. In this tutorial, we will learn how to create a basic navigation bar using CSS.
Step 1: Create the HTML Structure
First, let's create the HTML structure for the navigation bar. We will use an unordered list <ul> to create a list of links. Each link will be contained within a list item <li>.
<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>
Step 2: Style the Navigation Bar with CSS
Next, let's style the navigation bar using CSS. We will style the list items as inline-block elements to create a horizontal navigation bar. We will also add padding and margin to the list items for spacing.
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
display: inline-block;
margin-right: 20px;
}
a {
text-decoration: none;
color: #333;
}
Step 3: Add Hover Effects
We can add hover effects to the navigation bar to make it more interactive. When a user hovers over a link, we can change the background color or text color to indicate that it is clickable.
li:hover {
background-color: #f2f2f2;
}
a:hover {
color: #007bff;
}
Step 4: Final Result
Here is the final result of the CSS navigation bar:
| Home | About | Services | Contact |
You can further customize the navigation bar by adding background colors, borders, and other CSS properties to match the design of your website.