How to load different css based on browser type. I want to load different css for IE and Firefox in asp.net I'm usng IE8 and above and forefox 3 and above. please help me.
Request.Browser will give you complete browser information, where you can check version, browser name, browser type etc.
if(Request.Browser.Browser == "IE")
{
HtmlLink css = new HtmlLink();
css.Href = ResolveClientUrl("~/style/StyleSheet.css");
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}
You can use the following css conditional statement to load a css file for IE after the main css file for Firefox and other browsers. This allows you to re-use a lot of the same css code and only overwrite those properties that IE doesn't get right:
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="styles/browser.css" />
<![endif]-->
The conditional statement above applies to versions of IE less than or equal to IE6, but you can set this to whatever you like.
You can learn more about CSS conditional statements here: http://www.quirksmode.org/css/condcom.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With