CSS中!important的使用
来源:互联网 发布:cc免费顶级域名注册 编辑:程序博客网 时间:2024/04/30 19:43
http://www.cnblogs.com/yudy/archive/2013/05/27/3102825.html
本篇文章使用最新的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> <div class="testClass" style="color:red;"> 测试Css中的Important </div></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显示成蓝色的。
以上实例说明使用!important的css定义是拥有最高的优先级的。只是在ie6下出了一点小的bug,注意书写方式一般可以轻松避开的。
0 0
- css 中!important的使用
- CSS中!important的使用
- CSS中!important的使用
- CSS中!important的使用
- CSS中!important的使用
- CSS中 !important 的使用
- CSS中!important的使用
- CSS中 !important 的使用
- CSS中!important的作用
- css中!important的作用
- CSS中!important的作用
- css中!important的作用
- css中!important的作用
- css中!important的作用
- css中!important的作用
- CSS 中important的作用
- css中!important的作用
- css中!important的作用
- LinkedList
- 关于eclipse项目红色感叹号的解决办法
- javascript简介
- Mega Man's Mission UVA11795(状态压缩dp)
- ROS Learning-006 beginner_Tutorials 编译ROS程序包
- CSS中!important的使用
- 【linux系统学习笔记】Ubuntu文本界面和图像界面的切换
- It seems that the port 3306 is already in use.aer you sure you want to use this port
- 设计模式之Builder模式
- 【模拟】Codeforces 691B s-palindrome
- 面试之JAVA
- MP4文件格式的解析,以及MP4文件的分割算法
- 面试之JAVAWEB
- webstorm快捷键