内联 > ID选择器 > 类选择器 > 标签选择器
/* id选择器的权重时候0100 /
/ 类选择器的权重是0010 /
/ 标签选择器的权重是0001 /
/ 行内选择器的权重是1000 */
继承的权重是0
案例如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
color: red;
}
.demo {
color: blue;
}
p {
color: pink;
}
</style>
</head>
<body>
<div class="demo">
<p>张三的爸爸姓王</p>
</div>
</body>
</html>
p标签选择器的样式会覆盖从父元素继承过来的样式,修改样式时,一定要看该标签有没有被选中,再来计算权重。
那接下来,小伙伴们,搞一道题瞧一下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div p {
color: red;
}
#father {
color: blue;
}
p.c2{
color: pink;
}
</style>
</head>
<body>
<div class="c1" id="father">
<p class="c2">张三的爸爸姓王</p>
</div>
</body>
</html>