Forum Moderators: not2easy

Message Too Old, No Replies

Show "if IE" statement in stylesheet itself?

         

aw23

3:56 pm on May 11, 2008 (gmt 0)

10+ Year Member



I am not sure this is possible. I have been searching the net and haven't found any solutions for this.

Is it possible to include a "If IE" statement in the stylesheet itself? And how would you do this?

I am wondering about this because I only have one style tag which I need to be different for IE6 and lower.

aw23

3:57 pm on May 11, 2008 (gmt 0)

10+ Year Member



Edit: Apologies for the spelling mistakes in the topic title.

g1smd

4:27 pm on May 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I use PHP to detect True_IE and serve the modified code only to them.

The code also ignores Opera when it claims to be IE.

swa66

8:17 pm on May 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The conditional comments by Microsoft are in fact just html comments that IE interprets anyway.

So for conditional comments you need to be able to add <head> elements: e.g.:


<head>
...
<link rel="stylesheet" type="text/css" href="/style.css" />
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="/ie6.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="/ie7.css" />
<![endif]-->
...
</head>

If you don't want to override some of your css, but instead want totally different css, it too can be achieved by conditional comments, (but it's nasty as it's actually serving invalid html to standards compliant browsers).

E.g.: IE won't touch this stylesheet:


<![if !IE]>
<link rel="stylesheet" type="text/css" href="/style.css" />
<![endif]>

If you only want one CSS file to be served depending on what browser you see and are ready to deal with cloaked browsers, proxies and potential consequences for beign considered "cloaking" [you will serve e.g. GoogleBot different content from your average visitor!]
Then you can try to detect the browse and deliver content based on that. [Not something I'm willing to do]