Hi,
How can I style a menu bar, so that when the width of its container is between (ca.) 800px and 1200px, the menu items are distributed with an equal amount of padding on either side?
This is what I currently have:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Equally spaced nav bar</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#wrapper{
margin: 0 auto;
max-width: 1200px;
}
#nav {
width: 100%;
height:50px;
float: left;
margin: 0;
padding: 0;
list-style: none;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}
#nav li {
float: left;
}
#nav li a {
display: block;
padding: 15px 35px 17px 35px;
text-decoration: none;
font-size:16px;
font-weight: bold;
color: #26419a;
border-right: 1px solid #ccc;
}
#nav li:last-child a {
border-right: none;
}
#nav li a:hover {
background-color: #fff;
}
</style>
</head>
<body>
<div id="wrapper">
<ul id="nav">
<li><a href="index.html" class="selected">Home</a></li>
<li><a href="produkte.html">Produkte</a></li>
<li><a href="service.html">Service</a></li>
<li><a href="mietgeraete.html">Mietgeräte</a></li>
<li><a href="unser_team.html">Unser Team</a></li>
<li><a href="stihltesttag.html">Stihltesttag</a></li>
<li><a href="anfahrt.html">Anfahrt</a></li>
<li><a href="kontakt.php">Kontakt</a></li>
<li><a href="partner.html">Partner</a></li>
</ul>
</div>
</body>
</html>
This works great when the width of div#wrapper is 1200px.
When I decrease the size of the viewport to below 1200px however, menu items start being knocked off of the menu bar and on to the next line.
What I would ideally like is for the padding on the left and right of the menu items to adjust itself, so that all of the menu items remain on the same line.
Could anyone give me a clue as to how this can be achieved?
Here is the code in a CodePen.
Thanks in advance.