Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stack divs from top to bottom in CSS

Tags:

html

css

I have a list that goes like this:

<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>

using css float left, it looks like this in html:

1 2
3 4
5

Is it possible to style my divs to look like the following:

1 4
2 5
3

Hope someone can help, thanks!

like image 789
Funky Avatar asked Sep 01 '11 09:09

Funky


People also ask

How do you stack items in a div with CSS?

Using CSS position property: The position: absolute; property is used to position any element at the absolute position and this property can be used to stack elements on top of each other. Using this, any element can be positioned anywhere regardless of the position of other elements.

How do I make divs stack horizontally?

To align div horizontally, one solution is to use css float property. But a better solution is to to use CSS display:inline-block on all divs which needs to be aligned horizontally and place them in some container div.


1 Answers

@ funky; you can use css3 column-count property for this

css:

div#multicolumn1 {
        -moz-column-count: 2;
        -moz-column-gap: 50%;
        -webkit-column-count: 2;
        -webkit-column-gap: 50%;
        column-count: 3;
        column-gap: 50%;

}

check this link for a demo Div's in two columns

http://jsfiddle.net/sandeep/pMbtk/

note: it doesn't work in IE.

like image 152
sandeep Avatar answered Oct 19 '22 07:10

sandeep