George
George

Reputation: 2110

Display inline problem

Consider the following HTML structure:

<div id="footer">
                <div id="content">
                    <ul>
                        <li>
                            <ul>
                                <li>AAA</li>
                                <li>AAA</li>
                                <li>AAA</li>

                            </ul>
                        </li>
                        <li>
                            <ul>
                                <li>BBB</li>
                                <li>BBB</li>
                                <li>BBB</li>
                            </ul>
                        </li>
                    </ul>
                </div>
    </div>

Next I apply the following CSS:

#content ul {
    list-style: none;
}

#content ul li{
    display: inline;
}

The output is: AAA AAA AAA BBB BBB BBB The required output is:

AAA BBB 

AAA BBB 

AAA BBB

Any help will be greatly appreciated.

Upvotes: 0

Views: 228

Answers (7)

Tgr
Tgr

Reputation: 28160

Ordering content differently from how it appears in the source is a huge pain in the neck. You are probably better off with a table or a definition list where the AAA and BBB elements alternate. If that is not an option, you could use two fixed-width ul blocks floated to the left, with block li elements - depends on your design requirements (e. g. how much do the widths vary? should the elements line up vertically?)

Upvotes: 1

Simon Arnold
Simon Arnold

Reputation: 16157

#content ul{float:left; list-style:none;}
#content>ul li{float:left;} /*Only target fist-level li*/
#content li>ul>li{clear:both;}

This will display exactly what you try to acheive without using table.

Upvotes: 1

James Hill
James Hill

Reputation: 61793

It appears that AAA and BBB represent tabular data. Why not use a table?

<table>
    <tr>
        <td>
            AAA
        </td>
        <td>
            BBB
        </td>
    </tr>
    <tr>
        <td>
            AAA
        </td>
        <td>
            BBB
        </td>
    </tr>
</table>

Tables still have their place in web development. They are not inherently evil.

Upvotes: 1

Jose Faeti
Jose Faeti

Reputation: 12302

You may try with this instead

#content > ul > li {
    display: inline;
}

This way only the first <li> elements will receive the rule.

Edit

You may want to use float:left to achieve your result as shown in this fiddle.

Upvotes: 1

tw16
tw16

Reputation: 29575

You can achieve this by deleting #content ul li{display: inline;} and adding the rule below. Live example: http://jsfiddle.net/tw16/5E7Ac/

#content ul li ul{
    float: left;
}

Upvotes: 1

Geert
Geert

Reputation: 1814

You could just float both lists next to each other.

#content ul { list-style:none; }
#content > ul > li { float:left; margin-right:1em; }

http://jsfiddle.net/geertdd/Cu49F/1/

Upvotes: 1

Chris
Chris

Reputation: 3795

Have you tried changing #content ul li to #content ul ul li, this should fix the problem.

Upvotes: 0

Related Questions