Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering a div inside a li

I have the following piece of HTML:

<ul id="downmenu">
    <li class="copyright">
        <div>&copy; 2011. All rights reserved.</div>
    </li>
    <li class="twitter">
        <img src="images/twitter.png" alt="" />
    </li>
    <li class="facebook">
        <img src="images/facebook.png" alt="" />
    </li>
</ul>

And the following piece of CSS:

#downmenu {
    font-size:14px;
    border-top: 1px solid #666;
    clear: both;
    list-style-type: none;
    margin: 20px 0;
    overflow: hidden;
    padding: 11px 0 11px 34px;
    width: 870px;   
}

#downmenu li {
    float:left;
}

#downmenu li.copyright {
    margin-right:540px;
    height:36px;
}

#downmenu li.copyright div{
    margin: auto 0;
}

(I think) #downmenu li.copyright is set to 36px tall, and I want to centre vertically the div inside it. To achieve that I've used margin: auto 0;. But it isn't centered.

Any clue?

like image 832
VansFannel Avatar asked Dec 21 '25 05:12

VansFannel


2 Answers

Remove the div altogether and use line-height to center your text.

Setting the line height equal to the height of the li will center it vertically.

    #downmenu li.copyright {
    margin-right:540px;
    height:36px;
    line-height:36px;
}
like image 129
Jrod Avatar answered Dec 22 '25 20:12

Jrod


Try this:

#downmenu li.copyright {
    margin-right:540px;
    height:36px;
    display: table-cell;
    vertical-align: middle;
}
like image 22
Tetaxa Avatar answered Dec 22 '25 19:12

Tetaxa