2011-07-16 118 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]--> 

謝謝。