By esend7881 on
I'd like to add a CSS file "design-ie.css" to be launched only if the user is using IE.
I know in HTML we have [if IE7]
So something like
if ($user_is_using_ie) drupal_add_css(ie.css);
What is the Drupal way of doing this?
Thanks a lot!
Comments
Conditional Stylesheets module
You could try the Conditional Stylesheets module. Or take a look at the Garland theme's page.tpl.php and the phptemplate_get_ie_styles() function) in Garland's template.php file as an example of a fairly easy way to handle this.
Alternatively, you could just hard code the conditional stylesheet into your page.tpl.php. It's not the most elegant, but I think it's more efficient than adding the stylesheet through drupal_add_css().
Well I actually ended up
Well I actually ended up doing it this way:
Seems to work, no extra modules or anything like that.
Actually, I am wondering: Is
Actually, I am wondering:
Is the above method I used "good" programming practice?
good but dirty ..haha
good but dirty ..haha
Solution
I know this thread is quite old, but I came here searching for a solution to this problem. I didn't like the look of the above hack (any browsers spoofing as IE will get fed bad stylesheets - some browsers do this by default, some have an option that certain users enable), so I kept looking and eventually found this:
That will work also, but you
That will work also, but you still have the same situation where any browsers spoofing IE will be fed the IE stylesheet.
Contact me to contract me for D7 -> D10/11 migrations.
No you won't
As spoofing as IE only spoofs the UA - it doesn't cause the parsing of conditional html comments.