Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to layout list items in groups

Tags:

html

css

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    
like image 971
joshefin Avatar asked Jan 16 '23 20:01

joshefin


2 Answers

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.
  • CSS3 columns compatibility.
like image 86
David Thomas Avatar answered Jan 19 '23 11:01

David Thomas


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/

like image 38
sandeep Avatar answered Jan 19 '23 11:01

sandeep