Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does an inline-block div get positioned lower when it has content? [duplicate]

Tags:

css

If you have three identical divs positioned inline-block they are aligned perfectly. But if you put any content in any of the divs it drops down below the others. Why does it do that?

<div class="left">?</div>
<div class="center"></div>
<div class="right"></div>

div {
    display:inline-block;
    margin-:2px;
    height:100px;
    width:25px;
    border:1px solid black;
}​

http://jsfiddle.net/7kkC6/

better example: http://jsfiddle.net/7kkC6/9/

like image 496
user1757120 Avatar asked Nov 15 '12 01:11

user1757120


1 Answers

This is because vertical-align is by default set to baseline. You can fix your problem by setting it to top :

div {
    display:inline-block;
    margin-:2px;
    height:100px;
    width:25px;
    border:1px solid black;
    vertical-align: top;
}​

The demo here : http://jsfiddle.net/7kkC6/4/

like image 117
wakooka Avatar answered Sep 19 '22 07:09

wakooka