esc0rp 发表于 2024-10-10 04:50:38

【第2971期】前端研发怎么样更好的避免样式冲突?级联层(CSS@layer)


    <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> CSS 新东西了。今日前端早读课<span style="color: black;">文案</span>由 @Zhang Jiqi 分享,公号:vivo 互联网技术授权。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">正文从这<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>讲述了 CSS 中的级联层(CSS@layer),讨论了级联以及级联层的创建、嵌套、排序和浏览器支持<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;">1、</span>什么是级联层 (Cascade Layers)?1.1 级联层的官方定义<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>参看 Cascading and Inheritance Level 5(13 January 2022) 中 6.4 节所述:</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;"><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>会结合案例<span style="color: black;">来讲</span>清楚。</p>1.2 级联层为<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>为了使 CSS <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>中的一个场景,从场景去理解级联层在<span style="color: black;">处理</span>什么问题。</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;"><img src="https://mmbiz.qpic.cn/mmbiz_png/4g5IMGibSxt4iaShhRcibWI3YGDhiaXyNLnLicVLn6Y3GFyY25geG0vg2s3HcxmkFmUEsT8nwdkWx1tHiaR40NXqkvdQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>原来的 display 文案是红色,当<span style="color: black;">咱们</span>引入了一个第三方组件库,第三方库中有以下样式。</p> <span style="color: black;">/* <span style="color: black;">研发</span>者样式 */</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">/* 第三方库 */</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span> 5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span> 0.5em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 120px<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> display 文案变成绿色。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>想要将 display 文案的颜色由绿色改成红色<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> <span style="color: black;">/* <span style="color: black;">研发</span>者样式 */</span> <span style="color: black;">#app div.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">/* 第三方库 */</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span> 5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span> 0.5em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 120px<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>对优先级的影响在用户页面中重写</p> <span style="color: black;">/* 第三方库 */</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span> 5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span> 0.5em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 120px<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">/* <span style="color: black;">研发</span>者样式 */</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<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;">效果如下:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/4g5IMGibSxt4iaShhRcibWI3YGDhiaXyNLnL5tpZnUgDQsyj4BvkL19Db94dGBn68voTYfWcw4hL7jrFuf5YWfTDmQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></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;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> blue<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>第三方库的样式<span style="color: black;">常常</span>都在项目设置的通用样式<span style="color: black;">例如</span> common.css 后加载。</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>更高特异性的择器的语句或<span style="color: black;">运用</span>!important,这会使代码变得冗长<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>
    <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>器特异性之间。当有些 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>。</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;">第1</span>个<span style="color: black;">平常</span><span style="color: black;">研发</span>场景痛点的 css 代码如下:</p> <span style="color: black;">/* 排序层 */</span> <span style="color: black;"><span style="color: black;">@layer</span> reset<span style="color: black;">,</span> lib<span style="color: black;">;</span></span> <span style="color: black;">/* 通用样式 */</span> <span style="color: black;"><span style="color: black;">@layer</span> reset</span> <span style="color: black;">{</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> black<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 100px<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span> 1em<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 style="color: black;">咱们</span>将第三方库的样式<span style="color: black;">所有</span>放到lib层*/</span> <span style="color: black;">/*<span style="color: black;">这儿</span><span style="color: black;">通常</span><span style="color: black;">运用</span>@import导入的方式*/</span> <span style="color: black;">/*为了示例简单<span style="color: black;">咱们</span>简化了操作*/</span> <span style="color: black;"><span style="color: black;">@layer</span> lib</span> <span style="color: black;">{</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span>5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 130px<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;">/* <span style="color: black;">研发</span>者样式 */</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<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>上面的 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>继续往下看。</p><span style="color: black;">2、</span>理解级联层的前提 —— 级联 (cascade)2.1 什么是级联?<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS 中有两个重要的<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>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">指的是类似&nbsp;color,font-family,font-size,line-height&nbsp;等属性父元素设置后,子元素会继承的特性。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><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>简单理解为是 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>优先级排序输出给给定元素上属性值一个级联值。级联值是级联的结果。</p>2.2 当前级联的排序标准<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>参看 Cascading and Inheritance Level 5(13 January 2022) 中 6.1 节,</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">相比于 Cascading and Inheritance Level 4(14 January 2016) 中的定义有<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>了级联层。由此级联排序变成:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">起源和重要性(Origin and Importance)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上下文(Context)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">样式属性(Element-Attached Styles)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">层(Layers)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">特异性(Specificity)</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>)(Order of Appearance)</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>样式。</p>2.3 级联起源(Cascading Origins)<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2.3.1 三个核心起源</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">css 中<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>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">用户<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>(Web <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;">2.3.2 起源的优先级</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Css 声明的起源取决于它来自哪里,重要性在于它<span style="color: black;">是不是</span>用!important 声明。</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;">过渡</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;">重要用户</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;">动画</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;">普通用户</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>的声明优先级越高。过渡和动画<span style="color: black;">咱们</span><span style="color: black;">能够</span>暂时忽略。</p>2.4 <span style="color: black;">熟练</span>又陌生的!important<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>者,!important 会被<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>&nbsp;!important&nbsp;设计出来的初衷是<span style="color: black;">做为</span>整体级联中的一个特性,来平衡<span style="color: black;">研发</span>者、用户设置和浏览器内置之间对 css 优先级的影响能力。</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> &gt; 用户<span style="color: black;">源自</span> &gt; 用户代理<span style="color: black;">源自</span>(<span style="color: black;">能够</span>参看上文起源优先级中 6-8 的排序)。<span style="color: black;">然则</span>当 css 声明添加&nbsp;!important&nbsp;之后会使它们的优先<span style="color: black;">次序</span>颠倒(参看上文起源优先级中 2-4 的排序)。</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>看&nbsp;!important&nbsp;<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;">举个例子:</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>覆盖的重要样式。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">浏览器对<span style="color: black;">拥有</span> hidden 类型的 input 输入框设置了默认的展示属性并且将其声明为重要。</p> <span style="color: black;">input</span> <span style="color: black;">{</span> <span style="color: black;">display</span><span style="color: black;">:</span> none <span style="color: black;">!important</span><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;">看下面两张图例:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>张<span style="color: black;">能够</span>看出<span style="color: black;">咱们</span>对<span style="color: black;">拥有</span> hidden 类型的 input 输入框的展示属性设置<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;"><img src="https://mmbiz.qpic.cn/mmbiz_png/4g5IMGibSxt4iaShhRcibWI3YGDhiaXyNLnL8GbEUdVyLNe5jELazgVr4mtqXdJBatbicAOfXyJCIicm5yAxGqiaiakNvg/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></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;"><img src="https://mmbiz.qpic.cn/mmbiz_png/4g5IMGibSxt4iaShhRcibWI3YGDhiaXyNLnLTvjtwDibv0NicyStVsYT9Lw6Rhpn91G7J422kbzVrzHibIOduYyktGXYA/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></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>者在作者样式表中设置的规则没能覆盖用户代理样式表中的相同规则。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这验证了上面说的:在级联中&nbsp;!important&nbsp;会颠倒三大核心起源默认优先<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>了一个 chrome <span style="color: black;">掌控</span>台这边的 bug,看上面的<span style="color: black;">第1</span>张图例:没生效的规则不划删除线,生效的反而划删除线了。</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;"><img src="https://mmbiz.qpic.cn/mmbiz_png/4g5IMGibSxt4iaShhRcibWI3YGDhiaXyNLnLdqxQYccYyDcKbQrCq0pLEudyoJK2NHial3G0mFaHEIB7cy5xM7XrZXw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">font-size 的值<span style="color: black;">最后</span>是‘12pt ’。<span style="color: black;">由于</span>作者样式表中添加!important 的规则优先权高于用户样式表中普通规则。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">text-indent 的值<span style="color: black;">最后</span>是‘1em’。<span style="color: black;">由于</span>虽然两个样式表都标注了&nbsp;!important,<span style="color: black;">然则</span>标注&nbsp;!important&nbsp;用户声明优先级大于标注&nbsp;!important&nbsp;作者声明。</p>2.5 一张图带你理解级联<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;"><img src="https://mmbiz.qpic.cn/mmbiz_png/4g5IMGibSxt4iaShhRcibWI3YGDhiaXyNLnLbhtuZJ8VOjXLZ9S45Ekia2F2LQv1SkntLiczbzyibveicKD5LsxRibVSQVQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">照片</span><span style="color: black;">源自</span>:css-tricks</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>器特异性(selector specificity)只是级联中的一小部分。<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>!important 在级联中有特殊地位。他穿插在级联规则的各个<span style="color: black;">周期</span>并能颠倒优先级。</p><span style="color: black;">3、</span>级联层 (CSS@layer) <span style="color: black;">运用</span>探索3.1 @layer 是什么?<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>来看 MDN 上的定义:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">The @layer CSS at-rule is used to declare a cascade layer and can also be used to define the order of precedence in case of multiple cascade layers.</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>说 @layer 这个 at-rule(AT 规则) 用于声明级联层(cascade layer),<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;">At-rules 是什么?</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">At-rules <span style="color: black;">指的是</span>导 CSS <span style="color: black;">怎样</span>表现的 CSS 语句。它们以 at 符号 @ (U+0040 COMMERCIAL AT) 开头,后跟一个标识符,<span style="color: black;">包含</span>下一个分号 ; ( U+003B SEMICOLON) 或下一个 CSS 块之前的所有内容。</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>的 at-rule 有 @charset、@media、@font-face 、@keyframes 等。</p>3.2 @layer 的句法规则<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">@layer&nbsp;的句法如下:</p> <span style="color: black;"><span style="color: black;">@layer</span> layer-name</span> <span style="color: black;">{</span>rules<span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-name<span style="color: black;">;</span></span> <span style="color: black;"><span style="color: black;">@layer</span> layer-name<span style="color: black;">,</span> layer-name<span style="color: black;">,</span> layer-name<span style="color: black;">;</span></span> <span style="color: black;"><span style="color: black;">@layer</span></span> <span style="color: black;">{</span>rules<span style="color: black;">}</span>3.3 <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>多种方式创建级联层。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>种<span style="color: black;">办法</span>是:创建命名的级联层,其中<span style="color: black;">包括</span>该层的 CSS 规则,如下所示:</p> <span style="color: black;"><span style="color: black;">@layer</span> green</span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span> 5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span>0.5em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 120px<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> special</span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> rebeccapurple<span style="color: black;">;</span> <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>是单层,如下所示:</p> <span style="color: black;"><span style="color: black;">@layer</span> green<span style="color: black;">;</span></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">能够</span>一次定义多个层,如下:</p> @layer green<span style="color: black;">,</span> special<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>决定了层的优先级。与声明<span style="color: black;">同样</span>,<span style="color: black;">倘若</span>在多个层中找到声明,最后定义的层声明将<span style="color: black;">最后</span>生效。看下面代码:</p> <span style="color: black;"><span style="color: black;">@layer</span> green<span style="color: black;">,</span>special<span style="color: black;">;</span></span> <span style="color: black;"><span style="color: black;">@layer</span> green</span> <span style="color: black;">{</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span> 5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span> 0.5em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 120px<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> special</span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> rebeccapurple<span style="color: black;">;</span> <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;">效果如下图:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/4g5IMGibSxt4iaShhRcibWI3YGDhiaXyNLnLVRibSkDGpZtib9dtKu2TStL3ae2VZ8t1AjrEgXtOExh7D1qMpMv8sZXg/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">special 层中 item 样式规则将被应用即使它的特异性<span style="color: black;">小于</span> green 层中的规则。这是<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>的<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>后,<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>如下代码虽然 @layer green 重新声明了并在文件后方<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> <span style="color: black;"><span style="color: black;">@layer</span> green<span style="color: black;">,</span>special<span style="color: black;">;</span></span> <span style="color: black;"><span style="color: black;">@layer</span> special</span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> rebeccapurple<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> green</span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span> 5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span> 0.5em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 120px<span style="color: black;">;</span> <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;">效果如下:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></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>创建更简单的 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>
    <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> <span style="color: black;"><span style="color: black;">@layer</span></span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> black<span style="color: black;">;</span> <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>匿名层有如下缺点:</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><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>会很难找到特定的代码块。</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>。</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>是样式库的作者,并想将某些 css 代码不被<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> @import。CSS 原生支持 @import 导入其他 CSS 文件。</p> <span style="color: black;"><span style="color: black;">@import</span> <span style="color: black;"><span style="color: black;">url</span><span style="color: black;">(</span>index.css<span style="color: black;">)</span></span> <span style="color: black;">layer</span><span style="color: black;">(</span>index<span style="color: black;">)</span><span style="color: black;">;</span></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>支持匿名引入,例如:</p> <span style="color: black;"><span style="color: black;">@import</span> <span style="color: black;"><span style="color: black;">url</span><span style="color: black;">(</span>index.css<span style="color: black;">)</span></span> layer<span style="color: black;">;</span></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> @import 时候需要放在除 @charset 之外的样式规则前,否则<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>元素上的属性。请参阅 Provide an attribute for assigning ato a cascade layer #5853。</p>3.4 层的嵌套规则<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 style="color: black;">@layer</span> base</span> <span style="color: black;">{</span> <span style="color: black;">p</span> <span style="color: black;">{</span> <span style="color: black;">max-width</span><span style="color: black;">:</span> 70ch<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> framework</span> <span style="color: black;">{</span> <span style="color: black;"><span style="color: black;">@layer</span> base</span> <span style="color: black;">{</span> <span style="color: black;">p</span> <span style="color: black;">{</span> <span style="color: black;">margin-block</span><span style="color: black;">:</span> 0.75em<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span>theme</span> <span style="color: black;">{</span> <span style="color: black;">p</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> #222<span style="color: black;">;</span> <span style="color: black;">}</span> <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>为一棵树:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.base</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">framework</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">base</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.theme</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;">1.base</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.framework.base</p>3.framework.theme
    <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 style="color: black;">@layer</span> framework</span> <span style="color: black;">{</span> <span style="color: black;"><span style="color: black;">@layer</span> default</span> <span style="color: black;">{</span> <span style="color: black;">p</span> <span style="color: black;">{</span> <span style="color: black;">margin-block</span><span style="color: black;">:</span> 0.75em<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> theme</span> <span style="color: black;">{</span> <span style="color: black;">p</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> #222<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 style="color: black;">@layer</span> framework.theme</span> <span style="color: black;">{</span> <span style="color: black;">/* 这些样式会被添加到framework层里面的theme层 */</span> <span style="color: black;">blockquote</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span>rebeccapurple<span style="color: black;">;</span> <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;">看效果:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>3.5 层的排序规则<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;">第1</span>层优先级最低,最后一层优先级最高。<span style="color: black;">然则</span>,未分层的样式<span style="color: black;">拥有</span>最高优先级:</p> <span style="color: black;">/* 未分层 */</span><span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-1</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-2</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> orange<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-3</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> yellow<span style="color: black;">;</span> <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>
    <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;">2.layer-3</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.layer-2</p>4.layer-1
    <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;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></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>添加样式</p> <span style="color: black;">/* 定义在一个<span style="color: black;">地区</span> */</span> <span style="color: black;"><span style="color: black;">@layer</span> my-layer<span style="color: black;">;</span></span> <span style="color: black;">/* 其他样式*/</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> ...</p> <span style="color: black;">/* 在某个<span style="color: black;">地区</span>添加样式 */</span> <span style="color: black;"><span style="color: black;">@layer</span> my-layer</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span>3.6 加上&nbsp;!important&nbsp;之后的排序规则 <span style="color: black;">/* 未分层 */</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green <span style="color: black;">!important</span><span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-1</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red <span style="color: black;">!important</span><span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-2</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> orange <span style="color: black;">!important</span><span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-3</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> yellow <span style="color: black;">!important</span><span style="color: black;">;</span> <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>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">优先级<span style="color: black;">次序</span>如下:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1.!important layer-1</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2.!important layer-2</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.!important layer-3</p>4.!important 未分层样式
    <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;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></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>看到对应规则在 chrome 浏览器的<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>有问题。应该是 chrome 浏览器<span style="color: black;">研发</span>者<span style="color: black;">掌控</span>台的 bug。</p>3.7 嵌套层的排序规则 <span style="color: black;"><span style="color: black;">@layer</span> layer-1</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-2</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> orange<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> layer-3</span> <span style="color: black;">{</span> <span style="color: black;"><span style="color: black;">@layer</span> sub-layer-1</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> yellow<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;"><span style="color: black;">@layer</span> sub-layer-2</span> <span style="color: black;">{</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;">/* 未嵌套 */</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> blue<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;">/* 未分层 样式 */</span> <span style="color: black;">a</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> black<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>
    <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;">2.layer-3</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">-layer-3 未嵌套</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">-layer-3 sub-layer-2</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">-layer-3 sub-layer-1</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3.layer-2</p>4.layer-1
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>3.8 <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>:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">例如:</p> <span style="color: black;"><span style="color: black;">@media</span> <span style="color: black;">(</span><span style="color: black;">min-width</span><span style="color: black;">:</span> 600px<span style="color: black;">)</span></span> <span style="color: black;">{</span> <span style="color: black;"><span style="color: black;">@layer</span> layout</span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> x-large<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 style="color: black;">@media</span> <span style="color: black;">(</span><span style="color: black;">prefers-color-scheme</span><span style="color: black;">:</span> dark<span style="color: black;">)</span></span> <span style="color: black;">{</span> <span style="color: black;"><span style="color: black;">@layer</span> theme</span> <span style="color: black;">{</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<span style="color: black;">;</span> <span style="color: black;">}</span> <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>对应的级联层生效。<span style="color: black;">倘若</span>两者都匹配,<span style="color: black;">那样</span>图层<span style="color: black;">次序</span>将为 layout, theme 都生效。<span style="color: black;">倘若</span>两个都不匹配则不定义层。下图是两者都匹配的场景。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p><span style="color: black;">4、</span><span style="color: black;">此刻</span>就能<span style="color: black;">运用</span>级联层吗?4.1 <span style="color: black;">日前</span>浏览器支持程度<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">照片</span><span style="color: black;">源自</span>:developer.mozilla.org</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>支持 @layer 规则。所有浏览器厂商都支持的特性<span style="color: black;">将来</span><span style="color: black;">必定</span>比较实用。</p>4.2 W3C 鼓励<span style="color: black;">能够</span><span style="color: black;">做为</span><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;">CSS 的标准化流程由 W3C Cascading Style Sheets Working Group (CSSWG)——W3C 层叠样式列表小组以及独立 CSS 专家<span style="color: black;">构成</span>。W3C 本身并不制定标准,而是<span style="color: black;">做为</span>一个论坛式的平台,接收来自小<span style="color: black;">构成</span>员的提交,并<span style="color: black;">经过</span>会议来商讨制定标准,所有的提交以及讨论都是公开透明的,<span style="color: black;">能够</span>在 W3C 网站上看到会议的记录,<span style="color: black;">能够</span>简单分为 4 个大<span style="color: black;">周期</span>:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">工作草案 (WD)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">候选人<span style="color: black;">举荐</span> (CR)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">提议的<span style="color: black;">意见</span> (PR)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">W3C <span style="color: black;">举荐</span> (REC)</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;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">照片</span><span style="color: black;">源自</span>:w3.org</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">W3C <span style="color: black;">经过</span>状态码表示规范的成熟度。成熟度从低到高排序如下图。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">照片</span><span style="color: black;">源自</span>:w3.org</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">再看下图:<span style="color: black;">包括</span> layer 概念的标准讨论<span style="color: black;">已然</span>到达 CR <span style="color: black;">周期</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">照片</span><span style="color: black;">源自</span>:w3.org</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">W3C 鼓励从 CR <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><span style="color: black;">5、</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> “引入了一个第三方组件库<span style="color: black;">引起</span>样式覆盖 “的问题上。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">css 代码如下:</p> <span style="color: black;">/* 排序层 */</span> <span style="color: black;"><span style="color: black;">@layer</span> reset<span style="color: black;">,</span> lib<span style="color: black;">;</span></span> <span style="color: black;">/* 通用样式 */</span> <span style="color: black;"><span style="color: black;">@layer</span> reset</span> <span style="color: black;">{</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> black<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 100px<span style="color: black;">;</span> <span style="color: black;">padding</span><span style="color: black;">:</span> 1em<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 style="color: black;">咱们</span>将第三方库的样式<span style="color: black;">所有</span>放到lib层,<span style="color: black;">这儿</span><span style="color: black;">通常</span><span style="color: black;">运用</span>@import导入的方式,为了示例简单<span style="color: black;">咱们</span>简化了操作*/</span> <span style="color: black;"><span style="color: black;">@layer</span> lib</span> <span style="color: black;">{</span> <span style="color: black;">#app .item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> green<span style="color: black;">;</span> <span style="color: black;">border</span><span style="color: black;">:</span> 5px solid green<span style="color: black;">;</span> <span style="color: black;">font-size</span><span style="color: black;">:</span> 1.3em<span style="color: black;">;</span> <span style="color: black;">width</span><span style="color: black;">:</span> 130px<span style="color: black;">;</span> <span style="color: black;">}</span> <span style="color: black;">}</span> <span style="color: black;">/* <span style="color: black;">研发</span>者样式 */</span> <span style="color: black;">.item</span> <span style="color: black;">{</span> <span style="color: black;">color</span><span style="color: black;">:</span> red<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>放到 lib 层,将需要重置的<span style="color: black;">有些</span>样式放到 reset 层,自己<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>者样式简单不冗长。</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;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">级联层(CSS@layer)<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>。</p>参考资料:<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS Cascading and Inheritance Level 5</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">A Complete Guide to CSS Cascade Layers</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">The Future of CSS: Cascade Layers (CSS @layer)</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS 必学<span style="color: black;">基本</span>:理解 CSS 中的级联规则</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">详解日后定会大规模<span style="color: black;">运用</span>的 CSS @layer 规则</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">W3C Process Document</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Cascade Layers Explainer</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;">作者:@Zhang Jiqi</p><span style="color: black;">源自</span>:https://mp.weixin.qq.com/s/4M-RvnTq8rJuKDC3VZOONQ
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这期前端早读课</p>对你有<span style="color: black;">帮忙</span>,帮”&nbsp;
    <span style="color: black;">赞</span><span style="color: black;">
      <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;“一下,</p>期待下一期,帮”
    </span><span style="color: black;">&nbsp;在看</span><span style="color: black;">” 一下 。</span>




m5k1umn 发表于 2024-10-17 20:53:45

外贸网站建设方法 http://www.fok120.com/

4lqedz 发表于 2024-10-23 18:44:59

同意、说得对、没错、我也是这么想的等。
页: [1]
查看完整版本: 【第2971期】前端研发怎么样更好的避免样式冲突?级联层(CSS@layer)