views:

356

answers:

2

Hi, I have a CSS style using child selectors in an HTML page as follows:

<html>
    <head>

        <title>MSO Bug</title>
        <style type="text/css" media="screen,print">
            ol{list-style-type:decimal;}
            ol > ol {list-style-type:lower-alpha;}
            ol > ol >ol {list-style-type:lower-roman;}
        </style>    

    </head>
    <body>

     <div>
     <ol>
        <li><div>level1</div></li>
        <ol>
            <li><div>level2</div></li>
            <ol>
                <li><div>level3</div></li>
            </ol>
        </ol>
     </ol>

      </div>               
    </body>
</html>

In Firefox, the CSS works properly - the first list level starts with '1', the second with 'a', and the third with 'i' as expected.

But this doesn't work in IE7/8!

(I'm aware of descendent selectors - for some reason I can't use that here)

+3  A: 

Always set list-style and list-style-type properties to the ul (not the li).

ol { list-style-type: decimal; }
ol > li > ol { list-style-type: lower-alpha; }
ol > li > ol > li > ol { list-style-type: lower-roman; }

Update: Now that you’ve added the HTML to your question, it looks like a couple of things are wrong:

  1. You’re not declaring a doctype. Try adding <!doctype html> above the first line of your code.
  2. Your HTML for your main OL is invalid. You’re closing the LI elements too early. An OL element can’t have another OL as a direct child element. This is what it should look like:

    <ol>
     <li>
      <div>level1</div>
       <ol>
        <li>
         <div>level2</div>
         <ol>
          <li>
           <div>level3</div>
          </li>
         </ol>
        </li>
       </ol>
      </ol>
     </li>
    </ol>
    
Mathias Bynens
+1 to that Mathias. I fixed that basic error, and edited the post to include the complete page. Still doesn't work in IE7 (and continues to work in FF).
Raj
@Raj: Thanks for posting your HTML! I edited my answer.
Mathias Bynens
You're right. It's a combination of both the errors you've mentioned. Accepting your answer. Unfortunately, many RTF editors produce code such as the one I've given (e.g. the YUI editor).Need to find a workaround...Thanks nevertheless!
Raj
lists used to be able to be nested directly, but it has been deprecated..
Gaby
I'm confused that this answer works! Your CSS shouldn't work now, as the ol's are no longer directly related...
MatW
MatW - this doesn't actually work! Please see my comment above. However the explanation given by Mathias is the correct one, hence I accepted his answer.
Raj
+1  A: 

You need to specify a DOCTYPE for child descendants to work in IE7 / 8.

HTML 4.01 Strict:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;

HTML 4.01 Transitional:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd"&gt;&gt;

HTML 4.01 Frameset:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd"&gt;

Without the DOCTYPE, IE reverts to quirks mode and will only support descendant selectors, not child selectors.

MatW
I tried all three above by adding them before the <html>. None of them caused the CSS to work. How do I know which mode IE is in?
Raj
It should do; the error has nothing to do with putting <ol> in <li>... The above code is tested and works.
MatW
@MatW: That is invalid HTML.
Mathias Bynens
@Mathias Bynens. Sure, but the point is that the incorrect HTML isn't the problem, it's the lack of DOCTYPE. Incorrect HTML does confuse the issue though, so I'll rollback.
MatW
@Raj You can use javascript to find out what mode IE is in; "alert(document.compatMode);". It will say "BackCompat" if you're in quirks mode (bad), "CSS1Compat" if you're not (good).
MatW
Thanks MatW, that's useful info
Raj