Issue
After checking similar questions to this, none of the recommended solutions worked for me. I am trying to align li elements to be vertically centered in their div:
HTML:
<div id="navi">
<ul id="navilist">
<li><a href="#home">
<img src="Images/homelnk.jpg" alt="Home"/></a></li>
<li><a href="#SGU">SGU</a></li>
<li><a href="#SGJR">SGJR</a></li>
<li><a href="#REGISTRATION">REGISTRATION</a></li>
<!--<li><a href="#PHOTOS">PHOTO GALLERY</a></li>-->
<li><a href="#SCHOLARSHIP">SCHOLARSHIP</a></li>
<!--<li><a href="#CONTACT">CONTACT US</a></li>-->
<!--<li><a href="#SOCIALMEDIA">SOCIAL MEDIA</a></li>-->
<li><a href="#MERCHANDISE">MERCHANDISE</a></li>
<li><a href="#FORMS">FORMS</a></li>
<li><a href="#PAY">PAY FOR SGU</a></li>
</ul>
</div>
CSS:
#navi {
position: relative;
height: 50px;
width:auto;
background: #ed7a4f;
vertical-align:middle;
}
#navi li{
display: inline;
list-style-type:none;
padding: 0px 2px 5px 2px;
}
How would I maintain a horizontal list, but center the text vertically?
Solution
There's some tricks to getting vertical alignment to work. Here's a good stackoverflow answer about it. There's a good comment to the answer which explains why you need the empty span...
Well, I figured I'd offer you an alternative. You use an empty
<span>
because vertical-align aligns elements relative to their siblings. If an element has no siblings, it will not be vertically aligned.
I also made an update to your fiddle
Here's a snippet of the css:
span {
vertical-align: middle;
display: inline-block; }
ul{
margin:0; padding:0;
display:inline-block;
list-style-type:none;
vertical-align:middle; }
#navi {
height: 100px;
background: #ed7a4f;
}
#navi li{
display: inline-block;
padding: 5px; }
Answered By - Tim Mac Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.