How to style my unordered list like a table?

css, html

Solution

Well, here's one possible solution:

ul {
    width: 450px;           /* change it to whatever you like */
    position: relative;

    /* these should be probably already set up by `reset.css` */ 
    list-style-type: none;
    margin: 0;
    padding: 0;
}

ul:before, ul:after {
    text-align: center;
    display: block;
    border: 1px solid black;
    border-bottom: 0;
    width: 48%;
}

ul:before {
    content: 'col1';
    border-right: 0;    
}

ul:after {
    content: 'col2';
    position: absolute;
    top: 0;
    left: 48%;
    margin-left: 1px;    
}

li {
    text-align: right;
    width: 48%;
    float: left;
    border: 1px solid black;
    margin-bottom: -1px;
}

li:nth-child(even) {
    margin-left: -1px;
}

It works (JSFiddle; tested in Chrome, Firefox and Opera; `nth-child(even)` selector obviously fails in IE8, so you have to emulate it with class or other means; but otherwise it's still solid), but I admit I feel guilty about this. )

P.S. If you want to add padding to the "cell" contents, don't forget to change their widths as well, like here:

li {
    width: 47%;
    padding-right: 1%;
}

Problem

I have ONLY one `<UL>` and under that we have group of `<LI>` ``` <ul> <li>1<li> <li>2<li> <li>3</li> <li>4<li> </ul> ``` now I wanted to show them as TABLE, please help me with CSS, how can we show as a TABLE for above UL/LI in below table format, 2 LI set in one TR (two TD) and so on....

Original source