I have searched extensively and seen numerous examples on how to vertical-align
text using the vertical-align
property and the line-height
property. However, all my efforts seem to bear no fruit as I am unable to get my text to align vertically. How do I do vertically align text to be centered? The height
properties are not fixed so I can't use line-height
.
HTML
<nav>
<ul>
<li><a href="html/login.html">Login</a></li>
<li><a href="html/user_registration.html">Register</a></li>
<li><a href="#">Programmes Offered</a></li>
</ul>
</nav>
CSS
nav
{
height: 30%;
width: 100%;
}
nav ul
{
height: 100%;
margin: 0px;
}
nav ul li
{
height: 33%;
width: 100%;
vertical-align: middle;
}
Have you tried with
Your text is within the a tag, so adding a in the css may solve your problem :)
you may use a pseudo element displayed as an inline-box using full height of li and vertical-aligned to midlle. DEMO
edit
If you also reset
display
andvertical-align
on<a>
, links can be spread on a few lines (demo below):vertical-align aligns inline elements with their siblings.. unless used in a table cell.
I don't think there's a by-the-book way of vertically aligning.. but this should work:
D E M O