0

So I have a basic navigation list bar. However some of the items have two lines of text.

I'd like to vertical-align:middle the text, while still being able to hover and click in the list block.

HTML:

<div class="nav">
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/">Some Text</a></li> 
    <li><a href="/">Double<br>Line</a></li> 
    <li><a href="/">Something</a></li>  
</ul>
</div>

CSS:

.nav li {
    float: left;
}

.nav a {
    background: #000;
    display: block;
    padding: 10px;
    text-decoration: none;
    border-right: 2px solid #fff;
    font-size: 14px;
    text-align: center;
    color: #fff;
}
.nav a:hover {
    background: yellow;
    color: #000;
}

This probably explains it best: http://jsfiddle.net/ZmpXM/

Cheers

Nathan Waters
  • 1,173
  • 4
  • 13
  • 23

1 Answers1

1

It's not dynamic, but you can achieve that by adding

height: 34px;
display: table-cell;
vertical-align: middle;

to your .nav a style

http://jsfiddle.net/ZmpXM/1/

Michael Peterson
  • 1,123
  • 6
  • 14
  • There's no other way to do it without table-cell yeah? Apparently IE7 and down don't support it – Nathan Waters Jan 24 '13 at 07:05
  • You could do it using javascript/jquery - was just giving a pure css answer. More on the css version here: http://stackoverflow.com/questions/5553284/vertically-aligning-text-in-ie7-without-using-table-cell-property – Michael Peterson Jan 24 '13 at 07:08