码迷,mamicode.com
首页 > Web开发 > 详细

Css伪类权重

时间:2017-07-24 23:37:39      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:显示   red   focus   import   class   重要   它的   cti   style   

css样式的权重计算在css中有很重要的作用,会影响很多样式的显示,

css的权重按标签,class,id,inlinecss的权重分别是1,10,100,1000,还有一种就是!important, important是权重最高的,它的权重比内联样式还高。

上面这些都是大家很容易知道,今天我们要讨论的是伪类的权重

 

css中的伪类有:hover,visited,focus,active等,这些伪类的权重该怎么考虑呢。

看下面的例子:

<html>
<head>
<style type="text/css">

a:hover {
color:red;
}
#a-id {
color: green;
}
.a-class {
color: yellow;
}
</style>
</head>
<body>
<a id="a-id">I am Id and hover</a> //hover颜色不改变
<a>I am hover</a>//hover变红色
<a class="a-class">I am class and hover</a>//hover变红色
</body>
</html>

上面的代码说明css的权重: id〉伪类〉class

 

Css伪类权重

标签:显示   red   focus   import   class   重要   它的   cti   style   

原文地址:http://www.cnblogs.com/ycherry/p/7231454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!