1
I’m trying to create a horizontal menu but I’m having difficulties in vertical alignment.
Some menu items have line break and others do not.
I tried to create a CSS to configure the elements div
, ul
and li
so that they are aligned in the center vertically, but the items that do not have line breaking, are aligned in the base of the items that have line breaking.
I made an example at the Fiddle and I’d like your help: Code on the Fiddle
#menu{
background: #535454;
width: 100%;
overflow: hidden;
}
#menu ul{
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: block;
}
#menu ul li{
display: inline-block;
max-width: 150px;
text-align: center;
}
#menu ul li a{
color: #ffffff;
text-decoration: none;
display: block;
padding: 15px 10px;
text-transform: uppercase;
position: relative;
}
#menu ul li a:hover{
color: #333333;
background: #00a4e6;
}
<div id="menu">
<ul>
<li>
<a href="#">Proteção para Cabeça</a>
</li>
<li>
<a href="#">Luvas</a>
</li>
<li>
<a href="#">Proteção para Torax</a>
</li>
<li>
<a href="#">Botas</a>
</li>
<li>
<a href="#">Proteção para Pernas</a>
</li>
</ul>
</div>
Thank you all!
Why the Hover of a row items does not fill the whole space?
– user28595
@Diegof pq an inline-block is like a normal text character. It is not suitable for this type of menu. I probably wouldn’t even use it
ul
for a layout of this type, but you know how such "good practices" are :)– Bacco
@Bacco thanks for the tip! Now, how to solve the problem of the Hover of the items of a line, that Diegof mentioned, to occupy the whole space of ul ?
– Christiano Ribeiro Soares
@Christianoribeirosoares is like I said, inline-block is not for this kind of thing. Probably the best thing would be to switch to flexbox, or something like that.
– Bacco