您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

CSS:!important使用代码分享

2024/2/25 23:42:17发布26次查看
本篇文章使用最新的ie10以及firefox与chrome测试(截止2013年5月27日22:23:22)
css的原理:
我们知道,css写在不同的地方有不同的优先级, .css文件中的定义 < 元素style中的属性,但是如果使用!important,事情就会变得不一样。
首先,先看下面一段代码:
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>测试css中的!important区别</title> </head> <style type="text/css">.testclass{ color:blue !important; }</style><body> <p class="testclass" style="color:red;"> 测试css中的important </p></body></html>
虽然元素的style中有testclass类的定义,但是在上面的css定义中的用!important限定的定义却是优先级最高的,无论是在ie6-10或者firefox和chrome表现都是一致的,都显示蓝色。
这种情况也同时可以说明ie6是可以识别!important的,只是这个是ie6的一个缺陷吧。如果写成下面的样式,ie6是识别不出来的:
.testclass{ color:blue !important; color:red; }
这样,在ie6下展示的时候会显示成红色。
当然,也可以通过以下方式来让ie6识别:
.testclass{ color:blue !important; } .testclass{ color:red; }
通过以上方式也是可以让ie6显示成蓝色的。
以上就是css:!important使用代码分享的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product