1
The snippet below is working correctly, dividing the navigation bar into four items equally distributed horizontally. Run it to observe. But it is not as I would like: the width field (width
) of each item in the list is 25%
, And that only works because there are exactly four items on the list. I would like the CSS to maintain the equal distribution of items regardless of the amount of them in the HTML. It is 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>
Very good! I just added
width: 100%;
in the list items of the second example for the effect to be totally equal to the snippet of the question (the link is larger than the length of the text).– Piovezan
@Piovezan Yes you’re right, I retired when I was testing and forgot to put again with the dimension that matters.
– Isac