My divs are displaying a staircase effect, as shown below. Usually in tables you can use vertical-align: top
, not sure how to do this for divs.
____1_____
_____2_____
______3_____
The CSS I have so far is:
.areadiv
{
float:left;
display: inline-block;
height:auto;
margin:0 auto;
width:130px;
padding:5px;
}
The HTML is:
<div>
<div class="areadiv">
content
</div>
</div>
Your CSS doesn't make so much sense with the layout you're are trying to achieve, it should be:
.areadiv {
float: left;
display: block;
width: 130px;
padding: 5px;
}
The margin: 0 auto;
is used for centering container divs and you don't need the inline-block.
<div class="areadiv">
bartolsthoorn 2012-04-04 23:44
I'm with @bartolsthoorn that your CSS is quite confusing. But rather than using float I'd use only display: inline-block
. And when you use inline-block
you have to remember to set vertical-align
as well as most (all?) browsers default to middle
:
.areadiv {
display: inline-block;
vertical-align: top;
width: 130px;
padding: 5px;
}
That's all you need.
Ok firstly the width of the containing div must be set = or > than the combined widths of the floats, that's how it knows to move on to the next line.
For example..
.areadiv
{
display: inline-block;
vertical-align: top;
width: 130px;
padding: 5px;
}
.containerdiv
{
width: 421px; /* ( 130 + 10 ) x 3 + 1 just in case */
}
And the HTML:
<div class="containerdiv">
<div class="areadiv">
</div>
<div class="areadiv">
</div>
<div class="areadiv">
</div>
</div>