Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<ul> horizontal nav bar... vertically-align element

I currently have the following code. I am trying to get the second, third, and fourth "li" elements to vertically-align in the middle of the nav bar. The first "li" is an image, and the second-fourth are all text.

Here is a screenshot of it currently.

http://i49.tinypic.com/bfesl3.png

I have tried using "vertical-align:middle" and padding. Note that the second, third and fourth "li" elements appear vertically-aligned in the middle if viewed in Firefox but not in other browsers.

Here is the code I have.

<ul class = "nav">

<li><a href="index.html" style="border-right:1px #FFFFFF solid; padding-top:4.6px; padding-bottom:17.3px;"><img src="img/randomtitle.png" style="padding-left:8px;padding-top:8px;"/></a></li>
<li><a href="aboutme.html" style="vertical-align:middle;padding-top:32px;margin-left:-15px;padding-bottom:14px;padding-right:20px;border-right:1px #ffffff solid;">about me</a></li>
<li><a href="films.html" style="vertical-align:middle;padding-top:32px;margin-left:1px;padding-bottom:14px;padding-right:30.5px;border-right:1px #ffffff solid;">films</a></li>
<li><a href="contactme.html" style="vertical-align:middle;padding-top:32px;margin-left:-20px;padding-bottom:14px;padding-right:11px;border-right:1px #ffffff solid;">contact me</a></li>

<span class="navlinkimages">
<li><a href=  target="_blank"><img src="social/social_vimeo.png" height = "30px" style = "margin-right:-14px;"/></a></li>
<li><a href= target="_blank"><img src="social/social_youtube.png" height = "30px" style = "margin-right:-14px;"/></a></li>
<li><a href= target="_blank"><img src="social/social_facebook.png" height="30px" style = "margin-right:-14px;"/></a></li>
<li><a href=  target="_blank"><img src="social/social_twitter.png" height = "30px" style = "margin-right:-14px;" /></a></li>
</span>
</ul>`

CSS Code:

.nav {
    list-style-type:none;
    padding-left:0;
    margin-left:0;
    font-family:DinC;
    padding-bottom:5px;
    background-color: #000000;
    border-radius:5px;
    height:35px;
}

.navlinkimages {
  float:right;
  padding-top:5px;
}

.nav li {
  display:inline;
  vertical-align:middle;
}

ul.nav a:hover {
  color:#FA4B2A;
}

.nav li img {
  vertical-align:middle;
}

ul.nav a{
  text-decoration:none;
  margin-right:27px;
  color:#FFFFFF;
}

Is there a way to make it vertically-aligned on all browsers?

Thanks!

like image 771
01jayss Avatar asked Apr 25 '12 23:04

01jayss


2 Answers

Try this:

.nav li {
  display:inline;
  vertical-align:middle;
  line-height:35px;
}
like image 54
John Conde Avatar answered Oct 05 '22 22:10

John Conde


Give each of those li a's a class middle:

<li>
    <a class="middle" href="aboutme.html" style="REDACTED">about me</a>
</li>

Define middle like:

.middle {
    line-height: 35px; /** or same as ul height */
}

Inline elements are always vertically centered within their line-height.

DEMO

like image 34
calebds Avatar answered Oct 05 '22 22:10

calebds