
1、条件注释法。是IE浏览器专有的Hack模式。
微软官方推荐hack模式。
只在IE下生效。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <!--[if IE]>
这段文字只在IE浏览器显示
<![endif]-->
只在IE 6 下生效
<!--[if IE 6 ]>
这段文字只在IE 6 浏览器显示
<![endif]-->
只在IE 6 以上版本生效
<!--[if gte IE 6 ]>
这段文字只在IE 6 以上(包括)版本IE浏览器显示
<![endif]-->
只在IE 8 上不生效
<!--[if ! IE 8 ]>
这段文字在非IE 8 浏览器显示
<![endif]-->
非IE浏览器生效
<!--[if !IE]>
这段文字只在非IE浏览器显示
<![endif]-->
|
2、类内属性前缀法,属性前缀法是在CSS风格属性名称之前添加一些hack前缀。
只有特定浏览器才能识别,以达到预期的页面显示效果。
1 2 3 4 5 6 7 8 9 10 | color:red;
_color:red;
*color:red;
+color:red;
*+color:red;
[color:red;
color:red9;
color:red;
color:red!important;
|
3、选择器前缀法,针对某些页面表现不一致或需要特殊处理的浏览器。
在CSS选择器之前,添加一些只有特定浏览器才能识别的前缀。
1 2 3 4 5 6 | *html #demo { color : red ;}
*+html #demo { color : red ;}
:root #demo { color :red 9 ; } :
body:nth-of-type( 1 ) #demo { color : red ;}
head:first-child+body #demo { color : red ; }
|
以上就是css中hack的3种表现形式,希望对大家有所帮助。更多css学习指路:css教程
本文教程操作环境:windows7系统、css3版,DELL G3电脑。