Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load different css file based on browser

Tags:

c#

.net

css

asp.net

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.

like image 304
Ram Avatar asked Jul 16 '11 06:07

Ram


2 Answers

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);
    }
like image 147
Muhammad Akhtar Avatar answered Oct 09 '22 23:10

Muhammad Akhtar


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

like image 40
rolling stone Avatar answered Oct 09 '22 22:10

rolling stone