您好,欢迎访问一九零五行业门户网

CSS SpecificityCSS特性、权重、优先级-CSS specificity规则、_html/css_WEB-ITnose

css specificity
as mentioned above, css styles follow an order of specificity and point values to determine(确定) when styles override(覆盖) one another or take precedence(优先). nettuts recently had a nice article in which the point values for css were explained. they are like so:
elements - 1 points
classes - 10 points
identifiers - 100 points
inline styling - 1000 points
when in doubt, get more specific with your style declarations(声明). you can also use the !important declaration for debugging(调试) purposes if needed.
read more about css specificity:
html dog on specificity
smashing magazine on css specificity
中文:
css方面很多人都问过我,设定后的css后却没有效果,样式失效,样式冲突,
这种问题一般发生于新手,很多情况下是忽视了css中的权重specificity,
我试总结关于specificity方面的一些规则、算法及实例
希望对新人能有所帮助~!
作者:孙佳(http://www.sjweb.cn/ 貌似链接不可用了)
关于css specificity
css 的specificity 特性或称非凡性,它是衡量一个衡量css值优先级的一个标准,既然作为标准,就具有一套相关的判定规定及计算方式,specificity用一个四位的数字串(css2是三位)来表示,更像四个级别,值从左到右,左面的最大,一级大于一级,数位之间没有进制,级别之间不可超越。
在多个选择符应用于同一个元素上那么specificity值高的最终获得优先级。
选择符specificity值列表
selectors
选择符 syntax samples
语法 ensample
示例 specificity
特性
通配选择符(universal selector) * *.div { width:560px;} 0,0,0,0
类型选择符(type selectors) e1 td { font-size:12px;} 0,0,0,1
伪类选择符(pseudo-classes selectors) e1:link a:link { font-size:12px;} 0,0,1,0
属性选择符(attribute selectors) e1[attr] h[title] {color:blue;} 0,0,1,0
id选择符(id selectors) #sid #sj{ font-size:12px;}
0,1,0,0
类选择符(class selectors) e1.classname .sjweb{color:blue;} 0,0,1,0
子对象选择符(child selectors) e1 > e2 body > p {color:blue;} e1+e2
相邻选择符(adjacent sibling selectors) e1 + e2 div + p {color:blue;} e1+e2
选择符分组(grouping) e1,e2,e3 .td1,a,body {color:blue;} e1+e2+e3
包含选择符(descendant selectors) e1 e2 table td {color:blue;} e1+e2
规则:
1. 行内样式优先级specificity值为1,0,0,0,高于外部定义。
如:
sjweb
外部定义指经由或
其它类似信息

推荐信息