Let's say we have a html list like this:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
...
<li>10</li>
</ul>
How to, using css and/or java script, make a browser show it like this (in groups of four, with some margin between the groups):
1 2 5 6 9 10
3 4 7 8
Just use column-count
, float
and width
after wrapping the ul
in a parent element to which the column-count
rule can be applied:
.colWrap {
-webkit-column-count: 3;
-moz-column-count: 3;
-o-column-count: 3;
-ms-column-count: 3;
column-count: 3;
}
li {
float: left;
width: 50%;
}
Adjusted HTML:
<div class="colWrap">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
</div>
JS Fiddle demo.
References:
column-count
property.you can use css3 column-count
property for this:
Write like this:
.colWrap {
-webkit-column-count: 3;
-moz-column-count: 3;
-o-column-count: 3;
-ms-column-count: 3;
column-count: 3;
-webkit-column-width:20px;
-moz-column-width:20px;
}
li {
display:inline;
}
div{
width:120px;
}
Check this http://jsfiddle.net/rJTGJ/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With