1、css if hack條件語法
< !--[if ie]> only ie <![endif]-->
僅所有的win系統自帶ie可識別
< !--[if ie 5.0]> only ie 5.0 <![endif]-->
只有ie5.0可以識別
< !--[if gt ie 5.0]> only ie 5.0+ <![endif]-->
ie5.0包換ie5.5都可以識別
< !--[if lt ie 6]> only ie 6- <![endif]-->
僅ie6可識別
< !--[if gte ie 6]> only ie 6/+ <![endif]-->
ie6以及ie6以下的ie5.x都可識別
<!--[if lte ie 7]> only ie 7/- <![endif]-->
僅ie7可識別
< !--[if gte ie 7]> only ie 7/+ <![endif]-->
ie7以及ie7以下的ie6、ie5.x都可識別
<!--[if ie 8]> only ie 8/- <![endif]-->
僅ie8可識別
<!--[if ie 9]> only ie 9/- <![endif]-->
僅ie9可識別
注:在 if 後加 lt gte有不同效果 (參加其它參數同理)
<!–[if gte ie 8]> = 高於或者等於ie8版本
2、div+css實例
css實例一:
讓ie6-ie8顯示不同的內容,div css代碼如下:
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>div if條件實例</title> </head> <body> 你正在使用: <!--[if ie 7]> <h2>ie7</h2> <![endif]--> <!--[if ie 6]> <h2>ie6</h2> <![endif]--> <!--[if ie 8]> <h2>ie8</h2> <![endif]--> <!--[if ie 9]> <h2>ie9</h2> <![endif]--> <br><br> <strong>說明</strong>:如果你的浏覽器版本為多少即會顯示ie多少,針對ie6-ie9實驗</body> </html>
div+css實例二:說明:以上針對不同ie顯示不同網頁內容div+css實例實驗。
讓ie6-ie8顯示不同css樣式效果,div css代碼如下:
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>css if條件hack實例</title>
<!--[if ie 6]>
<style type="text/css">
.divcss{ color:#f00;}
</style>
<![endif]-->
<!--[if ie 7]>
<style type="text/css">
.divcss{ color:#ff0;}
</style>
<![endif]-->
<!--[if ie 8]>
<style type="text/css">
.divcss{ color:#00f;}
</style>
<![endif]-->
<!--[if ie 9]>
<style type="text/css">
.divcss{ color:#000;}
</style>
<![endif]-->
</head>
<body>
<div class="divcss">
div css實驗提示:<br>
我在ie6下是紅顏色,在ie7下是黃顏色,在ie8下是藍顏色,在ie9下是黑色
</div>
</body>
</html>
說明:以上實驗僅實驗ie6-ie9下if hack。