C# 基于浏览器加载不同的css文件
如何根据浏览器类型加载不同的css。 我想在asp.net中为IE和Firefox加载不同的css 我是usng IE8及以上和Foreox 3及以上。C# 基于浏览器加载不同的css文件,c#,.net,asp.net,css,C#,.net,Asp.net,Css,如何根据浏览器类型加载不同的css。 我想在asp.net中为IE和Firefox加载不同的css 我是usng IE8及以上和Foreox 3及以上。 请帮助我。您的主CSS应该是大多数浏览器(包括Firefox)支持的CSS。然后,您可以使用HTML条件语句加载特定于IE的样式表 <!--[if gt IE 7]> According to the conditional comment this is Internet Explorer greater than
请帮助我。您的主CSS应该是大多数浏览器(包括Firefox)支持的CSS。然后,您可以使用HTML条件语句加载特定于IE的样式表
<!--[if gt IE 7]>
According to the conditional comment this is Internet Explorer greater than IE8<br />
<link rel="stylesheet" type="text/css" href="IEgreatethan7.css">
<![endif]-->
或者如果你想说得具体一些
<!--[if IE 8]>
According to the conditional comment this is Internet Explorer equal to IE8<br />
<link rel="stylesheet" type="text/css" href="IE8.css">
<![endif]-->
您可以使用以下css条件语句在Firefox和其他浏览器的主css文件之后加载IE的css文件。这允许您重复使用大量相同的css代码,并且只覆盖IE未正确处理的属性:
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="styles/browser.css" />
<![endif]-->
上面的条件语句适用于小于或等于IE6的IE版本,但您可以随意设置
您可以在此处了解有关CSS条件语句的更多信息:将为您提供完整的浏览器信息,您可以在其中检查版本、浏览器名称、浏览器类型等
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);
}
如果你用谷歌搜索你的问题,你会找到你的答案: 客户端(javascript):
<!--[if IE 7]>
<link href="style-ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
谢谢。在javascript或样式表中,我应该将此代码放在哪里?仅在标题部分的html中,您是否检查了请求的链接。浏览器,您已经从中获得了所有信息,其次,我给您提供了代码,您如何在运行时包含css。如果有其他人,您也可以对Mozilla和chrome浏览器执行同样的操作。