My .cent class is for <li>
elements. I want to center the text of the <li>
both horizontally and vertically. text-align:center;
takes care of horizontal centering, but the vertical centering isn't working. What's the CSS trick for this?
.cent{
height:20px;
width:20px;
text-align:center;
vertical-align: middle;
}
Use line-height
property.
Set it equal to height of element, and text will be vertically centered.
.cent{
height: 20px;
width: 20px;
text-align: center;
/*vertical-align: middle;*/
line-height: 20px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With