欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!

针对分歧的IE阅读器版本,使用if条件来配置对应css花色,从而意图css hack
<!--[if IE]> Only IE <![endif]-->
一切的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可识别以内的css格局
<!--[if gte IE 6]> Only IE 6/+ <![endif]-->
IE6以及IE6以下的IE5.x都可辨认
<!--[if lte IE 7]> Only IE 7/- <![endif]-->
仅IE7可识别以内的css花式
格外注明ie8不能运用if前提来设置装备摆设div css格式,这里的“<!-”是css注解、css注释、css解释中用到不异,可以进入分明css 注释。这里应用css注释方式来妄想if前提匿伏条件,从而在别的不相符if前提阅读器下不展示前提及注解if前提里名目,你大要分明下css埋伏别的门径。

经过以上的if前提来对差别版本涉猎器挪用差距css名目来方案css hack办法。
实比以下:
尔后咱们只执行一个只要微软IE可辨认,火狐不辨认例子代码下列

 

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IE的if条件css hack实例</title>
<style type="text/css">
<!--[if IE]>
<!--
.ys1 {color: #FF0000}
-->
<![endif]-->
</style>
</head>

<body>
<p>&lt;!--[if&nbsp;IE]&gt;&nbsp;Only&nbsp;IE&nbsp;&lt;![endif]--&gt;</p>
<p>我是<span class="ys1">css5.com.cn</span>测试名堂
</p>
</body>
</html>


 

 

 

截图下列

左边为微软IE涉猎器,左边为火狐涉猎器,经过if前提对名堂设置装备摆设只在ie中起劝化后成果图。
额定说明的if前提在ie8中不克不及见效。

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/wenji/w52079.shtml