1. 程式人生 > >判斷IE6 CSS 通過判斷瀏覽器型別而載入不同的css樣式

判斷IE6 CSS 通過判斷瀏覽器型別而載入不同的css樣式

所有IE都起作用:

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

IE以外的瀏覽器起作用:

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

只有IE7起作用:

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

只有IE6起作用:

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

只有IE5起作用:

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

只有IE5.5起作用:

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

只對IE6及以下版本起作用:

<!--[if lt IE 7]>  <link rel="stylesheet" type="text/css" href="ie6-and-down.css"/> <![endif]-->
<!--[if lte IE 6]>  <link rel="stylesheet" type="text/css" href="ie6-and-down.css"/> <![endif]-->

只對IE7及以下版本起作用:

<!--[if lt IE 8]>  <link rel="stylesheet" type="text/css" href="ie7-and-down.css"/> <![endif]-->
<!--[if lte IE 7]>  <link rel="stylesheet" type="text/css" href="ie7-and-down.css"/> <![endif]-->

只對IE8及以下版本起作用:

<!--[if lt IE 9]>  <link rel="stylesheet" type="text/css" href="ie8-and-down.css"/> <![endif]-->
<!--[if lte IE 8]>  <link rel="stylesheet" type="text/css" href="ie8-and-down.css"/> <![endif]-->

只對IE6及以上版本起作用:

<!--[if gt IE 5.5]>  <link rel="stylesheet" type="text/css" href="ie6-and-up.css"/> <![endif]-->
<!--[if gte IE 6]>  <link rel="stylesheet" type="text/css" href="ie6-and-up.css"/> <![endif]-->

只對IE7及以上版本起作用:

<!--[if gt IE 6]>  <link rel="stylesheet" type="text/css" href="ie7-and-up.css"/> <![endif]-->
<!--[if gte IE 7]>  <link rel="stylesheet" type="text/css" href="ie7-and-up.css"/> <![endif]-->

只對IE8及以上版本起作用:

<!--[if gt IE 7]>  <link rel="stylesheet" type="text/css" href="ie8-and-up.css"/> <![endif]-->
<!--[if gte IE 8]>  <link rel="stylesheet" type="text/css" href="ie8-and-up.css"/> <![endif]-->

三、通常對IE6做這樣處理:
(本站就是這樣處理)
對於IE6及以下版本處理是很具有挑戰性.近來,人們都在呼籲對IE6要太在意,包括一些企業,一些網路應用,甚至是政府。現在有一個比讓這些在 IE6下讓人慘忍睹網站下地域更好解決方案,那就是單獨寫一個針對IE6精簡CSS樣式表,這樣至少會影響人們瀏覽網頁主要內容。然後再寫一個IE6以上版本及其它的瀏覽器正常CSS,這樣是很好?

<!--[if !IE 6]><!-->   <link rel="stylesheet" type="text/css" media="screen, projection" href="REGULAR-STYLESHEET.css" /> <!--<![endif]-->   <!--[if gte IE 7]>   <link rel="stylesheet" type="text/css" media="screen, projection" href="REGULAR-STYLESHEET.css" /> <![endif]-->   <!--[if lte IE 6]>   <link rel="stylesheet" type="text/css" media="screen, projection" href="http://universal-ie6-css.googlecode.com/files/ie6.0.3.css" /> <![endif]-->

四、如果你非要用HACK來解決話……請往下看
只對IE7起作用:

* html #div {     height: 300px; }

對非IE7起作用:

#div {     _height: 300px; }

只對IE6以上版本起作用:

#div {    height/**/: 300px; }
html->body #div {       height: 300px; }