Write CSS to create a horizontal navigation menu
Description: Create a dark horizontal menu with the links Home, About, Services and Contact, and a different background when the mouse is over a link.
Hint:
- Remove bullets with
list-style: none. - Use
display: flexon theul. - Style the
atags with padding, and add ana:hoverrule.
CSS horizontal navigation menu
<style>
.menu {
list-style: none;
margin: 0;
padding: 0;
display: flex;
background: #333;
}
.menu a {
display: block;
padding: 12px 18px;
color: white;
text-decoration: none;
}
.menu a:hover {
background: #0073aa;
}
</style>
<ul class="menu">
<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>
Output in the browser:
How it works
- A menu is a list of links.
display: flexon theulputs the items in one row. display: blockwith padding on the links makes the whole box clickable, not only the text.- On your page, the background of a link turns blue when you hover over it (the hover colour does not show in this box).
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |