Is there a way to make li
elements in a dynamically generated ul
have equal width and fit on one line using CSS, without knowing the number of li
s beforehand?
W3Schools provides an example of a fixed-width navigation bar here, but adding another li
disrupts the layout instead of scaling to accommodate it.
Here is the example they provide:
CSS:
ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
li
{
float:left;
}
a:link,a:visited
{
display:block;
width:120px;
font-weight:bold;
color:#FFFFFF;
background-color:#98bf21;
text-align:center;
padding:4px;
text-decoration:none;
text-transform:uppercase;
}
a:hover,a:active
{
background-color:#7A991A;
}
HTML:
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
Ideally, I would like to be able to add another li
and have the menu adjust gracefully.