hacks within CSS file

Discussion in 'CSS' started by jwalker80, Feb 1, 2007.

  1. #1
    Hi,

    Is there a way of using the hack

    <!--[if IE]>

    <![endif]-->

    within css code, or is there an alternative? to comply with recent versions of IE and Mozilla
     
    jwalker80, Feb 1, 2007 IP
  2. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Create a separate style sheet for IE, and place the following:

    <!--[if IE]>
    <link rel="stylesheet" type="text/css" href="path/to/ie_stylesheet.css" />
    <![endif]-->

    at the end of your pages' <head> section. Now, the code within this separate style sheet will only be called by IE. (alter your href path to suit your site, of course)
     
    the_pm, Feb 1, 2007 IP
  3. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Also make sure that the conditional comment (which is what it's called) comes after your regular stylesheet, so that IE can take advantage of the "cascading" part of "Cascading Style Sheets" :).

    If you need to target IE 5.01, IE 5.5 and IE 6 (but not IE 7) then use [if lt IE 7] instead of just plain old [if IE]. The closing conditional comment tag would remain the same.
     
    Dan Schulz, Feb 2, 2007 IP