Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Side-by-side blocks using CSS

I want to have block elements side-by-side. I don't don't want to use left, right, top, or anything similar.

HTML

<div class="iLB">LOLOLOL</div>
<div class="iLB">
    This is content.<br/>
    This is content.<br/>
    This is content.
</div>
<div class="iLB">This, too?</div>

CSS

.iLB {
    display: inline-block;
}

Live demo: jsFiddle

like image 253
Andrey Avatar asked Sep 21 '12 23:09

Andrey


People also ask

How do I show blocks side by side in CSS?

The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.

How do I put blocks side by side in HTML?

Using float and margin The left div is styled with width:50% and float:left – this creates the green colored div that horizontally covers half of the screen. The right div is then set to margin-left:50% – this immediately places it to the right of the left div.

How do I align two divs side by side in CSS?

To position the divs side by side, we are using the float property to float each . float-child element to the left. Since they are both floating to the left, they will display side by side if there's enough space for both to fit.


1 Answers

Use vertical-align:top;

.iLB {
    display: inline-block;
    vertical-align: top;
}​

JSFiddle: http://jsfiddle.net/97wDh/1/

like image 113
Daniel Li Avatar answered Oct 27 '22 19:10

Daniel Li