css 继承和层叠

css继承

1.css 可以继承的是背景(background)、字体(font)、文本(text) 宽高。浮动的元素不会继承。

2.css样式:浏览器默认样式、用户指定样式、作者定义样式。

3、css优先级(权值)

    选择器   a  b  c   d

    内嵌     1   0   0  0

     id       0   1   0   0 

 属性/伪类 0   0   1   0

元素         0   0    0   1

!important 最高 

一般:内嵌>内联/外部

eg:

#content div#main-content h2{

color:red;

}

#content #main-content>h2{

color:blue
07
}

body #content div[id="main-content"] h2{
color:green;

}

上个例子中两个标题的颜色都是红色。

权值的计算中,b为的权值永远不可能进到a,只能在b为相加。其他也一样

#main-content div.paragraph h2{

color:orange;

}

#main-content [class="paragraph"] h2{

color:yellow;

}

div#main-content div.paragraph h2.first{

color:pink;

}

原文地址:https://www.cnblogs.com/alicezq/p/4948490.html