inline-block

You can create a grid of boxes that fills the browser width and wraps nicely. This has been possible for a long time using float, but now with inline-block it's even easier. inline-block elements are like inline elements but they can have a width and height. Let's look at examples of both approaches.

The Hard Way (using float)

.box {
float: left;
width: 200px;
height: 100px;
margin: 1em;
}
.after-box {
clear: left;
}

<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="box">

I'm floating!

</div>
<div class="after-box">

I'm using clear so I don't float next to the above boxes.

</div>

The Easy Way (using inline-block)

You can achieve the same effect using the inline-block value of the display property.

16 / 20
  • Creative Commons License