Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertical align multiple lines of text to the middle

Tags:

html

css

I need to align multiple lines of text to the middle. Here is a rough guide of the markup I am working with.

<ul>
    <li>
        <a href='#'>This should be centered.</a>
    <li>
</ul>

The element that needs to be centered

So as you can see from my image, the "work" link should be centered vertically. I have the width and height set with vertical-align: middle;. I know you need to set the line height for it to actually work but theres the problem. If I set the line height to 72px (the height of the element) then some of the links will stretch down the page due to them taking up two lines.

The broken center

Is there a way of aligning multiple lines of text to the middle without using line-height?

like image 309
Olical Avatar asked Oct 12 '11 16:10

Olical


1 Answers

Use display:table-cell; in your li element.

li {
width:200px;
height:200px;
vertical-align:middle;
display:table-cell;
}

This will give you this effect:

enter image description here

like image 109
Rich Avatar answered Nov 30 '22 01:11

Rich