6

I'm struggling a bit with this CSS-issue: http://jsfiddle.net/timkl/JbEX8/

I want two divs to align horizontally using "display: inline-block", however when I add text to one of the divs, the alignment is off.

Is there a way to make the two divs align without resorting to floats?

This is my markup:

<div class="box">
    <p>Some text</p>
</div><!-- /box -->

<div class="box">
    <!-- No text -->
</div><!-- /box -->

This is my CSS:

body {
color: gray;
}

.box {
    background: #ccc;
    height: 100px;
    width: 200px;
    display: inline-block;   
}

Check out my example on jsfiddle: http://jsfiddle.net/timkl/JbEX8/

timkl
  • 3,299
  • 12
  • 57
  • 71

2 Answers2

9

Add vertical-align to class box:

vertical-align: middle;

Also see the updated jsfiddle.

scessor
  • 15,995
  • 4
  • 43
  • 54
3

You should float them:

.box {
    float: left;

    background: #ccc;
    height: 100px;
    width: 200px;
    display: inline-block;   
}

Demo: http://jsfiddle.net/JbEX8/1/

Do note that since you didn't define margins, there is no spacing between them.

Blender
  • 289,723
  • 53
  • 439
  • 496