Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Conditional comments

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #22565
    daGUY
    Member

    Given how many bugs, errors, and omissions there are in Internet Explorer’s support for CSS, it’s a good idea to have a separate stylesheet just for IE6/7 that you load only if the user is using one of those browsers. For example, you could put this in the head of your document:

    Code:

    This is called a conditional comment. Since the syntax is that of a regular HTML comment, the code inside will be ignored by every browser except IE6, which will recognize the special [if IE 6] statement and parse the code.

    But there’s an even simpler way to do this. Instead of using the [if IE 6] piece to load another stylesheet, use it to create a special wrapper <div> that will only appear if the browser is IE6. For example:

    Code:

    Test!

    (more code, etc.)


    Now, any time you need to change the styles for an element but only in IE6, just prefix the selector with "#ie6":

    Code:
    .box {width: 100px;}
    #ie6 .box {width: 200px;}

    Credit for this trick goes to Position is Everything :-)

Viewing 1 post (of 1 total)
  • The forum ‘Other’ is closed to new topics and replies.