2011-07-16 52 views

回答

6

Request.Browser会给你完整的浏览器信息,在这里你可以查看版本,浏览器名称,浏览器类型等

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); 
    } 
+0

我应该在代码隐藏处理它可以详细说明更多请 – Ram

+0

你检查Request.Browser的链接,你已经得到的每一个信息,其次,我已经给你的代码,你如何可以包括在CSS运行。 –

+0

在同样的你可以为Mozilla和铬浏览器,如果任何其他人以及。 –

2

您的主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]--> 
+0

我应该在JavaScript还是样式表中放置这段代码? – Ram

+0

只是在头部分的HTML – Michal

4

您可以使用下面的CSS条件语句后加载CSS文件IE适用于Firefox和其他浏览器的主要css文件。这使您可以重复使用相同的CSS代码的很多,只覆盖那些IE不能得到正确的属性:

<!--[if lte IE 6]> 
<link rel="stylesheet" type="text/css" href="styles/browser.css" /> 
<![endif]--> 

上面的条件语句适用于IE的版本低于或等于IE6少,但你可以将它设置为任何你喜欢的。

您可以了解更多关于CSS的条件语句的位置:http://www.quirksmode.org/css/condcom.html

2

您可以使用这样的。

<!--[if IE 7]> 
    <link href="style-ie.css" rel="stylesheet" type="text/css" /> 
<![endif]--> 

谢谢。