怎么样理解CSS样式表权重与优先级
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">怎样</span>理解CSS的权重,CSS是对样式的修饰,权重<span style="color: black;">表率</span>着某种级别,权重决定了你css规则<span style="color: black;">怎么样</span>被浏览器解析直到生效,css权重关系到你的css规则是<span style="color: black;">怎么样</span><span style="color: black;">表示</span>的。权重比较时,<span style="color: black;">能够</span>比较权重值,<span style="color: black;">然则</span><span style="color: black;">亦</span>有例外的<span style="color: black;">状况</span>:多层嵌套时,权重的比较<span style="color: black;">办法</span>有什么<span style="color: black;">区别</span>呢?请看完本文就<span style="color: black;">晓得</span>了,彻底<span style="color: black;">把握</span>CSS权重。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">CSS权重规则1</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">同<span style="color: black;">同样</span>式<span style="color: black;">倘若</span>设置多次(<span style="color: black;">便是</span><span style="color: black;">一样</span>的属性,<span style="color: black;">然则</span>属性值<span style="color: black;">区别</span>,写在<span style="color: black;">区别</span>的样式表中),权重高的样式会覆盖权重低的样式;</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">CSS权重规则2</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">区别</span>的样式<span style="color: black;">区别</span>的<span style="color: black;">选取</span>器,样式效果会进行叠加,<span style="color: black;">例如</span>一个div,行内样式表设置了宽400px,内部样式表设置了高100px,<span style="color: black;">外边</span>样式表设置了背景颜色为blue,<span style="color: black;">那样</span><span style="color: black;">最后</span><span style="color: black;">表示</span>为:宽400px,高100px,背景颜色为green的一个长方形。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://picx.zhimg.com/v2-684d6328cc529b68b193754653727eb9_l.jpg?source=f2fdee93" style="width: 50%; margin-bottom: 20px;">
<div style="color: black; text-align: left; margin-bottom: 10px;">
<div style="color: black; text-align: left; margin-bottom: 10px;">diveng</div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2 次咨询</span>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">5.0</span></div>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;">南通大学 工学硕士</div>
<div style="color: black; text-align: left; margin-bottom: 10px;">11271 次赞同</div>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;">去咨询</div>
</div>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><!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>
<!-- ③<span style="color: black;">外边</span>样式表 -->
<link rel="stylesheet" href="css/yanse.css">
<!-- ②内部样式表 -->
<style>
div{
height: 100px;
}
</style>
</head>
<body>
<!-- ①行内样式表 -->
<div style="width:400px;></div>
</body>
</html></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">外边</span>样式表yanse.css</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">div{
bac<span style="color: black;">公斤</span>round-color: green;
}</div>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">第1</span>步:行内>内部><span style="color: black;">外边</span></h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span>看一下CSS的3种样式表的权重(优先级):行内>内部><span style="color: black;">外边</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">规则:多个样式表修饰同一个元素的时候,<span style="color: black;">思虑</span>的是代码从上向下执行,后面的代码把前面的代码覆盖了,就近原则,谁挨着近实现的是谁的样式。</p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">比较<span style="color: black;">办法</span></h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以下为HTML代码</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><!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>
<!-- ③<span style="color: black;">外边</span>样式表 -->
<link rel="stylesheet" href="css/waibu.css">
<!-- ②内部样式表 -->
<style>
div{
width:200px;
height: 200px;
bac<span style="color: black;">公斤</span>round-color: yellow;
}
</style>
</head>
<body>
<!-- ①行内样式表 -->
<!-- style="width:100px;height:100px;bac<span style="color: black;">公斤</span>round-color:red" -->
<div ></div>
</body>
</html></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以下为<span style="color: black;">外边</span>样式表waibu.css文件</p>
<div style="color: black; text-align: left; margin-bottom: 10px;">div{
width:300px;
height:300px;
bac<span style="color: black;">公斤</span>r</div>
回顾历史,我们感慨万千;放眼未来,我们信心百倍。 你的见解独到,让我受益匪浅,非常感谢。 我深感你的理解与共鸣,愿对话长流。 楼主发的这篇帖子,我觉得非常有道理。 哈哈、笑死我了、太搞笑了吧等。
页:
[1]