CSS 三大特性
<h2 style="color: black; text-align: left; margin-bottom: 10px;">CSS 三大特性</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">概念:</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>多种CSS样式的叠加。</p>是浏览器处理冲突的一个能力,<span style="color: black;">倘若</span>一个属性<span style="color: black;">经过</span>两个相同<span style="color: black;">选取</span>器设置到同一个元素上,<span style="color: black;">那样</span>这个时候一个属性就会将另一个属性层叠掉。
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic1.zhimg.com/80/v2-fe2d49fd1c664e1f794a1b4b032e04e4_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">原则:</p>样式冲突,遵循的原则是就近原则。 那个样式离着结构近,就执行那个样式。样式不冲突,不会层叠。<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS层叠性执行口诀: 长江后浪推前浪,前浪死在沙滩上。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">CSS继承性</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">概念:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">子标签会继承父标签的某些样式,如文本颜色和字号。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">想要设置一个可继承的属性,只需将它应用于父元素<span style="color: black;">就可</span>。</p>简单的理解<span style="color: black;">便是</span>:子承父业。
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-5df1ef17cf57875b5b55d852588e5bce_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>:</p>恰当地<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>某个样式,<span style="color: black;">能够</span>给父级指定一个,这些<span style="color: black;">孩儿</span>继承过来就好了。子元素<span style="color: black;">能够</span>继承父元素的样式(text-,font-,line-这些元素开头的<span style="color: black;">能够</span>继承,以及color属性)。<h2 style="color: black; text-align: left; margin-bottom: 10px;">CSS优先级(重点)</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">概念:</p>定义CSS样式时,经常<span style="color: black;">显现</span>两个或<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>,就会<span style="color: black;">显现</span>优先级的问题。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-db013d5229a3356d3ee9c73bc22c1a62_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1. 权重计算公式</p>
<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> CSS Specificity(特殊性)</p>标签<span style="color: black;">选取</span>器计算权重公式继承<span style="color: black;">或</span> *0,0,0,0<span style="color: black;">每一个</span>元素(标签<span style="color: black;">选取</span>器)0,0,0,1<span style="color: black;">每一个</span>类,伪类0,0,1,0<span style="color: black;">每一个</span>ID0,1,0,0<span style="color: black;">每一个</span>行内样式 style=""1,0,0,0<span style="color: black;">每一个</span>!important <span style="color: black;">要紧</span>的∞ <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>进制,级别之间不可超越。</p>关于CSS权重,<span style="color: black;">咱们</span><span style="color: black;">必须</span>一套计算公式来去计算,这个<span style="color: black;">便是</span> CSS Specificity(特殊性)。
<div style="color: black; text-align: left; margin-bottom: 10px;">div { color: pink!important; }</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2. 权重叠加</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>器等,是有多个<span style="color: black;">基本</span><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>一个简单的加法计算:</p>div ul li ------> 0,0,0,3.nav ul li ------> 0,0,1,2a:hover -----—> 0,0,1,1.nav a ------> 0,0,1,1<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>:</p>数位之间<span style="color: black;">无</span>进制 <span style="color: black;">例如</span>说: 0,0,0,5 + 0,0,0,5 =0,0,0,10 而不是 0,0, 1, 0, <span style="color: black;">因此</span>不会存在10个div能赶上一个类<span style="color: black;">选取</span>器的<span style="color: black;">状况</span>。继承的权重是0 。<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>被选中。</p><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>权重是0,<span style="color: black;">由于</span>继承的权重为0 。<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">编程师笔记 <a style="color: black;"><span style="color: black;">http://www.</span><span style="color: black;">bcsbj.com</span></a></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><a style="color: black;"><span style="color: black;"><span style="color: black;">编程师笔记,一个记录编程的小<span style="color: black;">助手</span>! - 让编程更加方便。</span><span style="color: black;"><span style="color: black;"></span>bcsbj.com</span></span></a></div>
祝福你、祝你幸福、早日实现等。
页:
[1]