css引入方式的优先级
内联样式>内部样式>外部引入
也就是就近原则,谁距离元素近,谁的优先级就高
css选择器优先级
!important(权限至高无上)
用于提升某个直接选中标签的选择器中的某个属性的优先级的, 可以将被指定的属性的优先级提升为最高
例如:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
div{
width: 100px;
height: 100px;
background-color: red !important;
}
</style>
<body>
<div style="background-color: aquamarine;"></div>
</body>
</html>
使用内部样式给div的背景颜色设置了!important,就变为了红色
权重规则计算
不同的选择器权重值不同
内联样式,如style="…",权重为1000
id选择器,如#box,权重为100
类、伪类,如.box,权重为10
标签选择器、伪元素选择器,如 div span,权重为1
通配符选择器,权重为0,
继承的样式没有权值
当权重相等情况下,谁写在后面就听谁