I am trying to prevent my menu from overlapping onto itself when the viewport gets small and the menu items get pushed to the next line. Seems like a simple problem but I have spent hours on this problem with no avail.
nav {
position: absolute;
width: 100%;
text-align: center;
}
nav li {
display: inline-block;
}
nav a {
text-decoration: none;
padding: 1em;
margin: 1em;
border: 2px solid black;
}
<body>
<header>
<nav>
<ul>
<li><a href="#">NavItem</a>
</li>
<li><a href="#">NavItem</a>
</li>
<li><a href="#">NavItem</a>
</li>
<li><a href="#">NavItem</a>
</li>
<li><a href="#">NavItem</a>
</li>
</ul>
</nav>
</header>
</body>
Now shrink your window and the items all overlap.