tags:

views:

419

answers:

6

What is the most efficient way to make all nested list items the same size while using an em that is not equal to 1. For example, I want all li's in this list to be sized to 0.85em of the ul's parent. Do I have to create a separate class for each "level" of depth?

<html>
<head>
    <style type="text/css">
        li
     {
      font-size: 0.85em;
     }
    </style>
</head>
<body>
    <ul>
        <li>Level 1 item
            <ul>
                <li>Level 2 item
                    <ul>
                        <li>Level 3 item</li>
                    </ul>
                </li>
            </ul>
        </li>
    </ul>
</body>
</html>
A: 

I want all li's in this list to be sized to 0.85em of the ul's parent

body > ul { font-size: 0.85em; }

would do that

Bobby Jack
No, that still does the same thing because he has nested ul's.
jimyi
ok, edited .
Bobby Jack
Note: Will not work in IE6.
Emil Stenström
A: 
li { font-size: 0.85em; }
li li { font-size: 1em; }
David Dorward
A: 

My recommendation would be to give the first <ul> an id or class, and set the font-size there.

jimyi
A: 

(This answer assumes you want all li-elements the same size (you say both that you want the the same size, and different size in the question))

Font-size cascades, so if you just set it on the outer element (say a wrapper div or something), everything inside it will get one step smaller like (I think) you want to.

<div id="navigation">
    <ul>
        <li>...</li>
        <li>
        <ul><li>...</li><li>...</li></ul>
        </li>
    </ul>
</div>

#navigation { font-size: 0.85em; }
Emil Stenström
The example above works as it should though. Even in IE6, that doesn't support the child selector.
Emil Stenström
True - I was working with the HTML he gave us. He didn't specify browser compatibility, so I'm assuming he wants something that adheres to the CSS2.1 spec.
Bobby Jack
Where in the question does he say that he wants them to be different sizes?
Bobby Jack
"make all nested list items the same size" vs. "all li's in this list to be sized to 0.85em of the ul's parent". I'm leaning towards the first, but I can't be sure, and for some reason people are downvoting my answer, so I'm just trying to clarify.
Emil Stenström
Fair enough; I've un-downvoted your answer because this seems like a genuine misunderstanding, and your answer does work. But I think it's quite clear - "make all nested list items the same size" means, I assume, "... as each other". The other quote simply states that they should ALL be the computed value of 0.85em of the base font size - there's no inconsistency that I can see.
Bobby Jack
This example is kind of specific; what if one has several lists? A class would work, but is that semantic, or just redundant?
You
+3  A: 

Should work.

li li {font-size: 100%;}
Matt
It does, but it's not the most efficient way.
Bobby Jack
@Bobby, why is it not the most efficient way?
You
Without adding extra markup to your page this is the easiest way.
Matt
A: 

I agree with Emil, and would vote him up on this if I had enough rep points (n00b here). I would use a class like he mentions in his first point, so its re-usable in the same document. If you want cross browser and are using the current css spec then I cant suggest a better real world example..... roll on css 3 and the death of IE6 !

Crayonz
Thanks for the moral support! :)
Emil Stenström
Its how I would do it, and I think it was unfair to mark you down for actually being right and giving good advice
Crayonz