www.webdeveloper.com
Results 1 to 4 of 4

Thread: Conditional Comments Question

  1. #1
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063

    Conditional Comments Question

    How exactly do they work? What I'm getting at is all the time when I'm looking at source code on the internet, they're used to include external style sheets if the browser being used is some version of Internet Explorer. What I don't get is how that would help, because the default style sheets have already been written into the HTML. Wouldn't the different style sheets clash with each other

  2. #2
    Join Date
    Mar 2007
    Location
    USA
    Posts
    449
    Yes they would. I haven't see the pages you're talking about, but my guess is they're using one as a standard CSS base and then loading tweaks and fixes to replace non-working styles for certain browsers.
    infinityspiral.com

  3. #3
    Join Date
    Jan 2004
    Location
    chertsey, a small town s.w. of london, england.
    Posts
    1,459
    Hi there Joseph Witchard,

    I think that a simple example would be the best way to explain how a conditional comment works.

    In the example below, you will see that the div id="foo" has its color set to firstly to green and secondly to red.
    The methodology of CSS means that second rule will overide the first and set the color to red.
    This same principle applies to the conditional comment.
    IE reads the color as blue and this overides the red.
    Of course, for the conditional comment to be effective it must follow rather than precede the original stylesheet.
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    #foo {
        color:green;
        color:red;
    }
    </style>
    
    <!--[if IE]>
    <style type="text/css">
    #foo {
        color:blue;
     }
    </style>
    <![endif]-->
    
    </head>
    <body>
    
    <div id="foo">
    This text will colored red unless your browser is IE.
    If that is the case then it will be blue.
    </div>
    
    </body>
    </html>
    
    Further reading:-

    coothead

  4. #4
    Join Date
    Dec 2007
    Location
    Mississippi
    Posts
    1,063
    All right, thanks Both of you

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles