The snippet below is working correctly, dividing the navigation bar into four equally distributed items horizontally. Run it to observe. But it's not what I'd like: The width ( width
) field of each list item is 25%
, and this only works because there are exactly four items in the list. I would like CSS to keep the egalitarian distribution of items independent of their quantity in HTML. Is it possible?
* {
border: 0px;
margin: 0px;
padding: 0px;
border-width: 0px;
outline-width: 0px;
}
nav {
background-color: #a9eaff;
}
nav ul {
display: table;
width: 100%;
}
nav ul li {
list-style-type: none;
display: table-cell;
width: 25%;
text-align: center;
font-weight: bold;
}
nav ul li:hover {
background-color: blue;
text-color: white;
}
nav ul li a {
display: block;
text-decoration: none;
width: 100%;
height: 100%;
}
nav ul li a:hover {
color: white;
}
<nav>
<ul>
<li><a href="#">Início</a></li>
<li><a href="#">Ideias</a></li>
<li><a href="#">Tecnologias</a></li>
<li><a href="#">Demonstrações</a></li>
</ul>
</nav>