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,269
  • 10
  • 55
  • 70

2 Answers2

9

Add vertical-align to class box:

vertical-align: middle;

Also see the updated jsfiddle.

scessor
  • 15,965
  • 4
  • 40
  • 53
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
  • 275,078
  • 51
  • 420
  • 480