strike_noir strike_noir - 2 months ago 7
CSS Question

Style a cascade list into table

Just asking if there is a way to style a cascade list like this:

<ol>
<li>
<ol>
<li>col 1 row 1</li>
<li>column 2 row 1</li>
</ol>
</li>
<li>
<ol>
<li>column 1 row 2</li>
<li>col 2 row 2</li>
</ol>
</li>
</ol>


into a table like this

------------------------------------------------------
|col 1 row 1 |column 2 row 1 |
|column 1 row 2 |col 2 row 2 |
------------------------------------------------------


where each row is a horizontal list with the same width

I've been experimenting to achieve this, but can only get as close as this

------------------------------------------------------
|col 1 row 1 |column 2 row 1 |
|column 1 row 2 |col 2 row 2 |
------------------------------------------------------


I can't make each cell the same width.
Here is my css

ol.question_list {
list-style: decimal;
width: 100%;
}

ol.question_list li {
clear: both;
width: 100%;
}

ul.choice_list {
list-style: none;
padding: 0;
margin: 0 auto;
width: 100%;
}

ul.choice_list li {
display: inline;
list-style-type: none;
}


and here is my sample html

<ol class="question_list">
<li>
<ul class="choice_list">
<li>abc</li>
<li>defghi</li>
</ul>
</li>
<li>
<ul class="choice_list">
<li>abc12345</li>
<li>defghi12345</li>
</ul>
</li>
</ol>


Any ideas will be highly appreciated.

I've found the solution, but before I would like to thank for the response in this thread.
The solution is like this:

ol.row_list {
list-style: decimal;
padding: 0;
margin: 0 auto;
width: 100%;
}

ol.row_list li:after {
content: " ";
display: block;
line-height: 1px;
font-size: 1px;
clear: both;
}

ul.col_list {
list-style: none;
padding: 0;
margin: 0 auto;
width: 100%;
}

ul.col_list li {
display: block;
float: left;
width: 8%;
margin: 0;
padding: 0;
}

div {
display: table;
}


and the html looks like this

<div>
<ol class="row_list">
<li>
<ul class="col_list">
<li>abc
</li>
<li>12345
</li>
</ul>
</li>
<li>
<ul class="col_list">
<li>abc12345
</li>
<li>1234567890
</li>
</ul>
</li>
</ol>
</div>

Answer
.question_list {
    min-height: 10px; //clear float
}


.question_list li {
    display: block;
    float: left;
    width: 50%;
}

you try this?

Comments