css三大特性
一.层叠性
二.继承性
css代码
div{
color:red;
}
html代码
<div>
<p>继承</p>
</div>
三.优先级
1.权重计算公式(不是十进制)
不是10个标签选择器就等于1个类选择器
!important 无穷大
行内样式style="" 1000
id 100
类,伪类 10
标签 1
继承或者* 0
四.题目
1.
css:
#father{
color:red;
}
p{
color:blue;
}
html:
<div id="father">
<p>颜色</p>
</div>
结果字体显示为蓝色,因为p标签才直接选了字体
css:
#father #son{
color:blue;
}
#father p.c2{
color:black;
}
div.c1 p.c2{
color:red;
}
#father{
color:green !important;
}
html:
<div id="father" class="c1">
<p id="son" class="c2>
字体
</p>
</div>
虽然出现了improtant,但其没有选中内容,就没办法改变样式
所以字体是蓝色的