Navigation bars are the most critical part of any website. With CSS, you can turn a simple unordered list (<ul>) into a professional navigation menu.
All navigation bars start with a standard HTML list. We remove the bullets and padding first.
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
Making the links display as blocks ensures the whole area is clickable, not just the text.
li a {
display: block;
width: 200px; /* Optional width */
padding: 8px 16px;
text-decoration: none;
color: black;
}
li a:hover {
background-color: #2e7d52;
color: white;
}
To make the list horizontal, we can either use float: left; or display: inline-block; on the <li> elements.
li {
float: left; /* Aligns horizontally */
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
background-color: #333;
}
position: fixed; top: 0; width: 100%; to your navigation bar.