Pedro Lino
Pedro Lino

Reputation: 601

Display list item elements in different columns

I'm trying to change the looks of a DataLife Engine template, and I'm wondering if you could help me with alignment.

I have some info displayed in a colum, like this:

<div class="short-description">
    <div  class="table">
      <ul class="table">

        <li>A</li>

        <li class="odd">B</li>

        <li>C</li>

        <li class="odd">D</li>

        <li>E</li><br>

      </ul>
    </div>
</div>

This looks like

A
B
C
D
E

I want them to display like this:

A    B    C
D    E

The content of each "cell" can be different. E.g. if B has more contents, I'd like to adjust the columns as follows:

A    B    C
     B
     B
D    E

So it would stretch down until all info is displayed. The class odd just changes the color of that cell.

Here is the jsfiddle demo.

Upvotes: 0

Views: 152

Answers (2)

Hashem Qolami
Hashem Qolami

Reputation: 99524

In order to do that, you could display the list-items as inline-block elements, as follows:

ul {
    list-style: none;
    padding: 0;
    font: 0/0 a;  /* Remove space characters between inline-block elements */
}

ul li {
    font: 16px/1 Arial, sans-erif;  /* Reset the font property */
    display: inline-block;
    vertical-align: top;     /* <-- keep the inline elements at the top    */

    background-color: #ddd;  /* For the demo */
    margin: 5px;             /* For the demo */
    width: 200px;            /* For the demo */
}

JSFiddle Demo.

Upvotes: 3

oboshto
oboshto

Reputation: 3627

Look at jsfiddle

.table ul{
    list-style: none;
    width: 180px;
    height: auto;
}

.table li{
    display: inline-block;
    vertical-align: top;
    width: 50px;
    background: rgba(0,0,0,0.2);
    margin: 3px;
}

Upvotes: 1

Related Questions