Edit This Code:
<!DOCTYPE html>
<html>
<head>
<style>
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #dddddd;
}


li {
    float: left;
}


li a {
    display: block;
    padding: 8px;
}

</style>
</head>
<body>

<ul>
  <li><a href="tryit.asp-filename=trycss_navbar_horizontal_float2.html#home">Home</a></li>
  <li><a href="tryit.asp-filename=trycss_navbar_horizontal_float2.html#news">News</a></li>
  <li><a href="tryit.asp-filename=trycss_navbar_horizontal_float2.html#contact">Contact</a></li>
  <li><a href="tryit.asp-filename=trycss_navbar_horizontal_float2.html#about">About</a></li>
</ul>

<p>A background color is added to the list instead of each link to create a full-width background color.</p>
<p><b>Note:</b> overflow:hidden is added to the ul element to prevent li elements from going outside of the list.</p>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy