Browser Detection - Load Different CSS

Topics: Writing themes
Jan 5, 2012 at 5:20 PM

I've got a question I just can't seem to run down the answer to. I'd like to, as part of a code block, detect the browser and load specific CSS stylesheets depending on the browser. Doing it in code seems "cleaner" than doing it with a <!--[if IE]> tag or with Javascript. What am I missing?

Jan 5, 2012 at 7:03 PM

One option is Bertrand's theme switcher (part of Vandelay Industries module). You can have a number of themes that inherit from your base theme, and customise the CSS and layouts in each; so it's even more flexible than just CSS includes.

Jan 6, 2012 at 4:54 AM
Edited Jan 6, 2012 at 4:55 AM

I'm specifically trying to implement a third-party control on a custom page layout and need to include a different style if the browser is IE. Any way to do it in code? I would think there would be a quick way to assess the browser and branch in code. Am I wrong?

Jan 6, 2012 at 5:30 AM

I'd just use the conditionals ( <!--[if etc.) for something so specific. Orchard's Style.Include(...) syntax has additional methods for creating conditionals.