Validating Conditional Comments. HELP!

Discussion in 'CSS' started by Masterful, Mar 27, 2009.

  1. #1
    I'm trying to validate my CSS. I keep getting an error, caused by a downlevel-revealed conditional comment:

    <!--[if !IE]><!-->
    
    body {
    	font-size: 16px;
    }
    
    <!--<![B][[/B]endif]-->
    Code (markup):
    The error says, "Unknown error java.lang.RuntimeException: Encountered "[" at line 19, column 7". It refers to the first "[" in the closing tag of the conditional comment.

    I've checked everywhere and learnt that this is the valid way of doing a downlevel-revealed conditional comment. Apparently, the method provided by Microsoft is invalid:

    <![if !IE]>
    
    <![endif]>
    Code (markup):
    If I am using the valid method, why is it still not validating? :mad:

    I've also tried the following, which doesn't validate, either.

    <!--[if !IE]>-->
    
    <!--<[endif]-->
    Code (markup):
    Any ideas?
     
    Masterful, Mar 27, 2009 IP
  2. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #2
    Because it's invalid.
    <!--[if IE]>
    <![endif]-->
     
    drhowarddrfine, Mar 27, 2009 IP
  3. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #3
    I'm talking about down-level revealed conditional comments, not down-level hidden conditional comments. Here's an explanation of their differences:

    IE Conditional Comments
     
    Masterful, Mar 27, 2009 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
        <!--[if !ie]>-->
        <p>ie doesn't see this.</p>
        <!--[endif]>-->
    
        <![if !ie]>
        <p>second thing that ie doesn't see</p>
        <![endif]>
    
        <!--[if !IE]><!-->
        <p>third thing.</p>
        <!--<![endif]-->
    Code (markup):
    All three work equally well. The second is not valid, but works because browsers are supposed to ignore unknown tags. IE reads it as ignore everything until the endif statement.

    CCs one and three validate. Personally, I'd go with the first version.

    cheers,

    gary
     
    kk5st, Mar 27, 2009 IP
  5. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #5

    None of them validate for me. That's what I am trying to say.

    Here is the error that I'm getting now:

    "Encountered "[" at line 13, column 7. Was expecting: <EOF>"

    Line 13, column 7 is the opening square bracket ([) of the closing tag of the conditional comment. Why isn't it validating for me?
     
    Masterful, Mar 28, 2009 IP
  6. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #6
    My CSS is external. I'm using the conditional comment in accordance with the method explained on this page, which concerns the best practice to follow when sizing text in CSS.
     
    Masterful, Mar 28, 2009 IP
  7. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #7
    The CCs may not be used in the stylesheet. They belong in the html document. You are not using them in accordance to the article.

    cheers,

    gary
     
    kk5st, Mar 28, 2009 IP
    Masterful likes this.
  8. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #8
    Thanks, Gary. That explains it. One rep point for you. :)
     
    Masterful, Mar 28, 2009 IP
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #9
    Uhm, conditional comments are HTML only. Once you open a <style> tag or in an external CSS, they're invalid since you are no longer writing HTML, you are writing CSS, and there are NO IE CC's for CSS, and frankly forget validation, that shouldn't even work in the browser...

    <!--[if !IE]><!-->
    <style type="text/css">
    body {
    font-size: 16px;
    }
    </style>
    <!--<![endif]-->

    SHOULD validate...

    NOT that you should have to target IE for something like a font tag, or use CC's for CSS in the first place. 10 to 1 the problem you are trying to circumvent with that is not so much with IE as it is with your CSS and/or markup.

    If we could see the offending page or a demonstration of why you are trying to do that in the first place, we could probably be of more help - though you might not care for the answers.
     
    deathshadow, Mar 28, 2009 IP