css选取器优先级秩序是什么?css基本选取器优先级的介绍
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">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>,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>介绍css<span style="color: black;">选取</span>器优先级的排序,话不多说,<span style="color: black;">咱们</span>来直接看正文内容。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><a style="color: black;"><span style="color: black;"><span style="color: black;">web前端学习:打造全网web前端全栈资料库(总目录)看完学的更快,<span style="color: black;">把握</span>的更加<span style="color: black;">牢靠</span>,你值得<span style="color: black;">持有</span>(<span style="color: black;">连续</span>更新)</span><span style="color: black;">154 </span></span></a>赞同 · 6 评论<span style="color: black;"><span style="color: black;">文案</span></span></div>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">在看css<span style="color: black;">选取</span>器优先级<span style="color: black;">次序</span>前,<span style="color: black;">咱们</span>先来简单说说css基本<span style="color: black;">选取</span>器有<span style="color: black;">那些</span>?</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1、标记<span style="color: black;">选取</span>器(如:body,div,p,ul,li)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2、id<span style="color: black;">选取</span>器(如:id="name",id="name_txt")</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3、类<span style="color: black;">选取</span>器(如:id="name",id="name_txt")</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">4、后代<span style="color: black;">选取</span>器(如:#head .nav ul li 从父集到子孙集的<span style="color: black;">选取</span>器)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">5、子元素<span style="color: black;">选取</span>器(如:div>p ,带大于号>)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">6、伪类<span style="color: black;">选取</span>器(如:<span style="color: black;">便是</span>链接样式,a元素的伪类,4种<span style="color: black;">区别</span>的状态:link、visited、active、hover。)</p>看完了基本的css<span style="color: black;">选取</span>器类型后,<span style="color: black;">咱们</span>接着来看一下css优先级的概念。当两个规则都<span style="color: black;">功效</span>到了同一个html元素上时,<span style="color: black;">倘若</span>定义的属性有冲突,<span style="color: black;">那样</span>应该用谁的值的,用到谁的值谁的优先级就高。<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">咱们</span>来看一下css<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>规则对应一个初始"四位数":0、0、0、0</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">若是 行内<span style="color: black;">选取</span>符,则加1、0、0、0</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">若是 ID<span style="color: black;">选取</span>符,则加0、1、0、0</p>
<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>符,则分别加0、0、1、0</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">若是 元素<span style="color: black;">选取</span>符,则分别加0、0、0、1</p>算法:将每条规则中,<span style="color: black;">选取</span>符对应的数相加后得到的”四位数“,从左到右进行比较,大的优先级越高。 <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>css<span style="color: black;">选取</span>器优先级的<span style="color: black;">详细</span>排序。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">css<span style="color: black;">选取</span>器优先级最高到最低<span style="color: black;">次序</span>为:</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.id<span style="color: black;">选取</span>器(#myid)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.类<span style="color: black;">选取</span>器(.myclassname)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.标签<span style="color: black;">选取</span>器(div,h1,p)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">4.子<span style="color: black;">选取</span>器(ul < li)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">5.后代<span style="color: black;">选取</span>器(li a)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">6.伪类<span style="color: black;">选取</span>(a:hover,li:nth-child)</p>
<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>的是: </p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">!important的优先级是最高的,但<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>,则采用就近原则,<span style="color: black;">选取</span>最后<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>本篇<span style="color: black;">文案</span>的<span style="color: black;">所有</span>内容,关于css<span style="color: black;">选取</span>器当然不止<span style="color: black;">以上</span>的六个<span style="color: black;">选取</span>器,<span style="color: black;">更加多</span>css<span style="color: black;">选取</span>器的内容<span style="color: black;">能够</span>参考<a style="color: black;">css<span style="color: black;">运用</span>手册</a>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以上<span style="color: black;">便是</span>css<span style="color: black;">选取</span>器优先级<span style="color: black;">次序</span>是什么?css基本<span style="color: black;">选取</span>器优先级的介绍的<span style="color: black;">仔细</span>内容,<span style="color: black;">更加多</span>请关注我!!!!</p>
你的见解真是独到,让我受益良多。 我完全同意你的看法,期待我们能深入探讨这个问题。 楼主继续加油啊!外链论坛加油!
页:
[1]