{"id":10412,"date":"2022-05-22T22:34:18","date_gmt":"2022-05-22T14:34:18","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10412"},"modified":"2022-05-22T22:35:06","modified_gmt":"2022-05-22T14:35:06","slug":"deep-in-css-cascade","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2022\/05\/deep-in-css-cascade\/","title":{"rendered":"CSS\u5fc5\u5b66\u57fa\u7840\uff1a\u7406\u89e3CSS\u4e2d\u7684\u7ea7\u8054\u89c4\u5219"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10412\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10412<\/a> \u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202205-cascade.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/css-cover.png\" width=\"480\" height=\"305\" alt=\"CSS\u7ea7\u8054\u5c01\u9762\u56fe\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<h3>\u4e00\u3001\u7b80\u8ff0<\/h3>\n<p>CSS\u4e2d\u6709\u4e24\u4e2a\u91cd\u8981\u7684\u57fa\u7840\u89c4\u5219\uff0c\u4e00\u4e2a\u662f\u7ea7\u8054\uff08Cascading\uff09\uff0c\u4e00\u4e2a\u662f\u7ee7\u627f\uff08Inheritance\uff09\u3002<\/p>\n<p>\u7ee7\u627f\u6307\u7684\u662f\u7c7b\u4f3c color, font-family, visibility \u7b49\u5c5e\u6027\u7236\u5143\u7d20\u8bbe\u7f6e\uff0c\u5b50\u5143\u7d20\u4f1a\u88ab\u7ee7\u627f\u7684\u7279\u6027\u3002<\/p>\n<p>\u90a3\u7ea7\u8054\u6307\u7684\u662f\u4ec0\u4e48\u5462\uff1f<\/p>\n<p>\u5728 JS \u4e2d\uff0c\u65b9\u6cd5\u7684\u8fde\u7eed\u6267\u884c\u53ef\u4ee5\u79f0\u4e3a\u7ea7\u8054\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>var fn = {\r\n  a: function () {\r\n    return this;\r\n  },\r\n  b: function () {\r\n    return this;\r\n  }\r\n};\r\n\/\/ \u7ea7\u8054\u8c03\u7528\r\nfn.a().b();<\/pre>\n<p>CSS\u4e2d\u7684\u7ea7\u8054\u4e0e\u4e0a\u9762\u795e\u4f3c\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u5e94\u7528\u67d0\u4e2a CSS \u6837\u5f0f\u7684\u65f6\u5019\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\u6709\u5f88\u591a\u7684\u524d\u540e\u5e94\u7528\u65b9\u6cd5\u3002<\/p>\n<pre>fn.styleA().styleB().styleC()...<\/pre>\n<p>\u6700\u7ec8\u8be5\u5e94\u7528\u54ea\u4e2a CSS \u6837\u5f0f\uff0c\u5c31\u662f\u57fa\u4e8e\u8fd9\u4e9b\u7ea7\u8054\u89c4\u5219\u6765\u7684\u3002<\/p>\n<p>\u6309\u7167\u76ee\u524d\u7684 <a href=\"https:\/\/drafts.csswg.org\/css-cascade-4\/#cascading\" rel=\"noopener\" target=\"_blank\">CSS \u89c4\u8303<\/a>\u7684\u63cf\u8ff0\uff0cCSS \u7ea7\u8054\u7684\u4f18\u5148\u7ea7\u662f\u8fd9\u6837\u7684\uff08\u6309\u5e8f\u53f7\u9012\u51cf\uff09\uff1a<\/p>\n<ol>\n<li>transition \u8fc7\u6e21\u58f0\u660e\uff1b<\/li>\n<li>\u8bbe\u7f6e\u4e86 !important \u7684\u6d4f\u89c8\u5668\u5185\u7f6e\u6837\u5f0f\uff1b<\/li>\n<li>\u8bbe\u7f6e\u4e86 !important \u7684\u7528\u6237\u8bbe\u7f6e\u7684\u6837\u5f0f\uff1b<\/li>\n<li>\u524d\u7aef\u5f00\u53d1\u8005\u5728 @layer \u89c4\u5219\u4e2d\u8bbe\u7f6e\u7684\u5305\u542b !important \u7684\u6837\u5f0f\uff1b<\/li>\n<li>\u524d\u7aef\u5f00\u53d1\u8005\u5e73\u5e38\u8bbe\u7f6e\u7684\u5305\u542b !important\u7684\u6837\u5f0f\uff1b<\/li>\n<li>animation \u52a8\u753b\u58f0\u660e\uff1b<\/li>\n<li>\u524d\u7aef\u5f00\u53d1\u8005\u8bbe\u7f6e\u7684 CSS \u6837\u5f0f\u3002<\/li>\n<li>@layer \u89c4\u5219\u4e2d\u7684\u6837\u5f0f\uff1b<\/li>\n<li>\u7528\u6237\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbe\u7f6e\u7684\u6837\u5f0f\uff1b<\/li>\n<li>\u6d4f\u89c8\u5668\u81ea\u8eab\u5185\u7f6e\u7684\u6837\u5f0f\uff1b<\/li>\n<\/ol>\n<p>\u6655\u4e86\u6655\u4e86\uff01<\/p>\n<p>\u90fd\u4ec0\u4e48\u8ddf\u4ec0\u4e48\uff0c\u4e0d\u6025\uff0c\u4e14\u542c\u6211\u5a13\u5a13\u9053\u6765\u3002<\/p>\n<h3>\u4e8c\u3001\u7ea7\u8054\u89c4\u5219\u8be6\u89e3<\/h3>\n<h4>1. \u5148\u4e0d\u7528\u7ba1 !important<\/h4>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u6211\u4eec\u7406\u89e3\uff0c\u6211\u4eec\u53ef\u4ee5\u5148\u4e0d\u7528\u5173\u5fc3 !important \u5bf9\u7ea7\u8054\u4f18\u5148\u7ea7\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u7406\u8bba\u4e0a\u7684\u7ea7\u8054\u4f18\u5148\u7ea7\u662f\uff1a<\/p>\n<pre>transition &gt; animation &gt; \u5e38\u89c4CSS &gt; @layer\u89c4\u5219 &gt; \u7528\u6237\u8bbe\u7f6e &gt; \u6d4f\u89c8\u5668\u5185\u7f6e<\/pre>\n<h4>2. \u4e5f\u4e0d\u7528\u7ba1 transition \u548c animation<\/h4>\n<p><code>transition<\/code> \u548c <code>animation<\/code> \u58f0\u660e\u4e0b\u7684\u7ea7\u8054\u89c4\u5219\u5927\u5bb6\u4e5f\u53ef\u4ee5\u4e0d\u7528\u592a\u5173\u5fc3\uff0c\u4e3a\u4ec0\u4e48\u5462\uff1f<\/p>\n<p>\u4e3b\u8981\u662f\u6d4f\u89c8\u5668\u7684\u771f\u5b9e\u8868\u73b0\u548c\u89c4\u8303\u4e2d\u5b9a\u4e49\u7684\u5e76\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u4f8b\u5982\u8bbe\u7f6e\u4e86 !important \u5c5e\u6027\u7684 CSS \u5e94\u8be5\u4f18\u5148\u7ea7\u6bd4 <code>animation<\/code> \u9ad8\uff0c\u4f46\u662f\uff0c\u5728 IE\uff0cIE Edge\uff0cChrome \u4ee5\u53ca Safari \u6d4f\u89c8\u5668\u4e0b\uff0c\u52a8\u753b\u6267\u884c\u7684\u4f18\u5148\u7ea7\u662f\u6700\u9ad8\u7684\uff0c\u8d85\u8d8a <code>!important<\/code>\u3002<\/p>\n<p>\u300aCSS\u65b0\u4e16\u754c\u300b\u4e2d\u6709\u4e13\u95e8\u4ecb\u7ecd\u8fc7\uff0c<a href=\"https:\/\/demo.cssworld.cn\/new\/5\/4-1.php\" rel=\"noopener\" target=\"_blank\">demo\u89c1\u8fd9\u91cc<\/a>\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/animation-opacity.jpg\" width=\"640\" height=\"335\" alt=\"CSS\u65b0\u4e16\u754c\u4e2d\u7684animation\u4f18\u5148\u7ea7\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u81f3\u4e8e <code>transition<\/code> \u7684\u6700\u9ad8\u4f18\u5148\u7ea7\u66f4\u662f\u65e0\u4ece\u8c08\u8d77\uff0c\u6211\u53cd\u590d\u6d4b\u8bd5\uff0c\u90fd\u662f\u666e\u901a CSS \u5c5e\u6027\u7684\u8868\u73b0\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u6211\u4eec\u5e94\u8be5\u5173\u5fc3\u7684\u7ea7\u8054\u4f18\u5148\u7ea7\u5176\u5b9e\u5c31\u8fd9\u4e48\u51e0\u4e2a\uff1a<\/p>\n<pre>\u5e38\u89c4CSS &gt; @layer\u89c4\u5219 &gt; \u7528\u6237\u8bbe\u7f6e &gt; \u6d4f\u89c8\u5668\u5185\u7f6e<\/pre>\n<h4>3. \u5e38\u89c1\u4e14\u91cd\u8981\u7684\u56db\u79cd\u7ea7\u8054\u89c4\u5219<\/h4>\n<p><strong>\u5e38\u89c4CSS<\/strong><\/p>\n<p>\u6240\u8c13\u5e38\u89c4 CSS\uff0c\u6307\u7684\u662f\u5f00\u53d1\u4eba\u5458\u5728 CSS \u6587\u4ef6\uff0c<code>&lt;style&gt;<\/code> \u5143\u7d20\uff0c\u6216\u4f7f\u7528 HTML <code>style<\/code> \u5185\u8054\u5c5e\u6027\u8bbe\u7f6e\u7684 CSS\u6837\u5f0f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/2022-05-22_203451.png\" width=\"682\" height=\"393\" alt=\"\u5f00\u53d1\u8005 CSS \u4ee3\u7801\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p><strong>@layer\u89c4\u5219<\/strong><\/p>\n<p>CSS @layer \u89c4\u5219\u662f\u6700\u8fd1\u73b0\u4ee3\u6d4f\u89c8\u5668\u7eb7\u7eb7\u652f\u6301\u4e86\u4e00\u4e2a\u6781\u5177\u98a0\u8986\u6027\u7684\u65b0\u7279\u6027\uff0c\u517c\u5bb9\u6027\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/2022-05-22_200650.png\" width=\"639\" height=\"276\" alt=\"@layer \u89c4\u5219\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u8fd9\u4e2a\u89c4\u5219\u53ef\u4ee5\u8ba9\u5176\u4e2d\u8bbe\u7f6e\u7684\u6240\u6709 CSS \u7684\u4f18\u5148\u7ea7\u964d\u4f4e\uff0c\u7279\u522b\u9002\u5408\u5728\u5f15\u5165\u67d0\u4e2a\u6a21\u5757\u7684\u65f6\u5019\u4f7f\u7528\uff0c\u53ef\u4ee5\u4f18\u5148\u907f\u514d\u4ed6\u4eba\u7684\u4ee3\u7801\u56e0\u4e3a\u4f18\u5148\u7ea7\u539f\u56e0\u5f71\u54cd\u81ea\u5df1\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;button id=\"button\"&gt;\u6211\u662f\u6309\u94ae&lt;\/button&gt;<\/pre>\n<pre>button {\r\n  color: red;\r\n}\r\n@layer {\r\n  #button {\r\n    color: green;\r\n  }\r\n}<\/pre>\n<p>\u6b64\u65f6\u867d\u7136 ID \u9009\u62e9\u5668\u7684\u4f18\u5148\u7ea7\u5f88\u9ad8\uff0c\u4f46\u7531\u4e8e\u5728 @layer \u89c4\u5219\u4e2d\uff0c\u4f18\u5148\u7ea7\u6ca1\u6709\u5916\u9762\u7684\u6807\u7b7e\u9009\u62e9\u5668 button \u9ad8\uff0c\u56e0\u6b64\u6309\u94ae\u662f\u7ea2\u8272\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/2022-05-22_205557.png\" width=\"214\" height=\"138\" alt=\"layer \u7b80\u5355\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5173\u4e8e @layer \u89c4\u5219\u6211\u4f1a\u5728\u4e0b\u4e00\u7bc7\u6587\u7ae0\u4e2d\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p><strong>\u7528\u6237\u8bbe\u7f6e<\/strong><\/p>\n<p>\u7528\u6237\u8bbe\u7f6e\u7684 CSS \u591a\u6307\u7528\u6237\u5b89\u88c5\u63d2\u4ef6\u7b49\u5de5\u5177\u6240\u8bbe\u7f6e\u7684 CSS\uff08\u79f0\u4e3a\u201c\u6ce8\u5165\u7684\u6837\u5f0f\u8868\u201d\uff09\uff0c\u6bd4\u65b9\u8bf4 Adblock \u7b49\u63d2\u4ef6\u5bf9\u9875\u9762\u5143\u7d20\u9690\u85cf\u7684 CSS \u5c31\u5c5e\u4e8e\u8fd9\u4e00\u7c7b\u3002<\/p>\n<p>\u4ee5\u53ca\uff0c\u6211\u4e2a\u4eba\u8ba4\u4e3a\uff08\u5b9e\u9645\u5e76\u4e0d\u51c6\u786e\uff09\uff0c\u7528\u6237\u901a\u8fc7\u6d4f\u89c8\u5668\u81ea\u8eab\u7684\u8bbe\u7f6e\u6539\u53d8\u6d4f\u89c8\u5668\u7684\u4e3b\u9898\u80cc\u666f\uff0c\u5b57\u53f7\u6216\u5b57\u4f53\u7b49\u4e5f\u53ef\u4ee5\u5f52\u4e3a\u8fd9\u4e00\u7c7b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/2022-05-22_202245.png\" width=\"704\" height=\"171\" alt=\"\u6d4f\u89c8\u5668\u7684\u8bbe\u7f6e\" class=\"alignnone size-medium\" \/><\/p>\n<p><strong>\u6d4f\u89c8\u5668\u5185\u7f6e<\/strong><\/p>\n<p>\u5b98\u65b9\u8bf4\u6cd5\u53eb\u505a\u7528\u6237\u4ee3\u7406\u6837\u5f0f\uff0c\u5176\u5b9e\u5c31\u662f\u6d4f\u89c8\u5668\u5185\u7f6e\u7684\u6837\u5f0f\u3002<\/p>\n<p>\u8fd9\u4e2a\u5927\u5bb6\u90fd\u89c1\u5f97\u6bd4\u8f83\u591a\uff0c\u5f88\u591a HTML \u5143\u7d20\u4f1a\u5185\u7f6e\u6837\u5f0f\uff0c\u5e38\u89c1\u7684\u5982 <code>&lt;body&gt;<\/code>, <code>&lt;p&gt;<\/code> \u7b49\u5143\u7d20\u7684 <code>margin<\/code> \u5916\u95f4\u8ddd\uff0c<code>&lt;input&gt;<\/code>\u3001<code>&lt;button&gt;<\/code>\u7b49\u5143\u7d20\u7684\u8fb9\u6846\u548c\u80cc\u666f\u8272\u6837\u5f0f\u7b49\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/2022-05-22_202601.png\" width=\"363\" height=\"279\" alt=\"\u7528\u6237\u4ee3\u7406\u6837\u5f0f\u8868\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e0a\u9762\u8fd9\u56db\u79cd\u7c7b\u578b\u5c31\u662f\u76ee\u524d\u4e3b\u8981\u7684\u7ea7\u8054\u89c4\u5219\u3002<\/p>\n<p>\u6bcf\u4e00\u79cd\u7ea7\u8054\u89c4\u5219\u7684\u4f18\u5148\u7ea7\u90fd\u662f\u8d85\u8d8a\u4e0b\u4e00\u4e2a\u7ea7\u8054\u89c4\u5219\u7684\uff0c\u9664\u975e\u4f7f\u7528 <code>!important<\/code> \u8fdb\u884c\u9006\u88ad\uff0c\u5426\u5219\u662f\u65e0\u6cd5\u91cd\u7f6e\u3002<\/p>\n<h4>4. \u9006\u5411\u8fd0\u4f5c\u7684 important \u6807\u8bc6\u7b26<\/h4>\n<p><code>!important<\/code> \u6709\u4e2a\u5f88\u6709\u610f\u601d\u7684\u7279\u6027\uff0c\u90a3\u5c31\u662f\u539f\u672c\u7ea7\u8054\u6c34\u5e73\u9ad8\u7684CSS\u58f0\u660e\u5e94\u7528\u4e86<code>!important<\/code>\u540e\uff0c\u5176\u4f18\u5148\u7ea7\u53cd\u800c\u4f4e\uff0c\u800c\u539f\u672c\u7ea7\u8054\u6c34\u5e73\u4f4e\u7684 CSS \u58f0\u660e\u5e94\u7528\u4e86 <code>!important<\/code> \u540e\uff0cCSS \u8ba1\u7b97\u7684\u4f18\u5148\u7ea7\u53cd\u800c\u9ad8\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u7528\u6237\u4ee3\u7406 CSS\uff08\u6d4f\u89c8\u5668\u5185\u7f6e CSS\uff09\u5728\u7ea7\u8054\u89c4\u5219\u4e2d\u5904\u4e8e\u5e95\u5c42\uff0c\u4f46\u662f\uff0c\u4e00\u65e6\u8fd9\u4e9b\u5c5e\u6027\u503c\u7684\u540e\u9762\u589e\u52a0\u4e86 !important\u3002<\/p>\n<p>\u4e0d\u5f97\u4e86\uff01\u7edd\u5730\u5927\u7ffb\u8eab\uff0c\u8d85\u7ea7\u5927\u9006\u88ad\uff0c\u4f18\u5148\u7ea7\u76f4\u63a5\u5347\u5230\u8d85\u7ea7\u9738\u4e3b\u7684\u5730\u4f4d\uff0c\u5b8c\u5168\u4e0d\u53ef\u64bc\u52a8\uff01<\/p>\n<p>\u5982\u679c\u6211\u4eec\u5e73\u65f6\u6bd4\u8f83\u654f\u611f\uff0c\u5c31\u4f1a\u770b\u5230\u6d4f\u89c8\u5668\u5185\u7f6e\u7684\u4e0d\u5c11 CSS \u540e\u9762\u8bbe\u7f6e\u4e86 !important\u3002<\/p>\n<p>\u8ddf\u5927\u5bb6\u8bb2\uff0c\u8fd9\u4e9b CSS \u6837\u5f0f\u4f60\u5c31\u4e0d\u8981\u767d\u65e5\u505a\u68a6\uff0c\u8bf4\u7684\u662f\u6211\u53bb\u91cd\u7f6e\u4ed6\uff01<\/p>\n<p>\u778e\u5b50\u70b9\u706f\u767d\u8d39\u8721\uff0c\u4e00\u70b9\u6bdb\u7528\u90fd\u6ca1\u6709\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/2022-05-22_210800.png\" width=\"519\" height=\"167\" alt=\"\u65e0\u6cd5\u91cd\u7f6e\u7684 CSS \" class=\"alignnone size-medium\" \/><\/p>\n<p>\u540c\u6837\u7684\uff0cChrome \u6709\u5f88\u591a\u5e7f\u544a\u62e6\u622a\u63d2\u4ef6\uff0c\u5176\u4f1a\u901a\u8fc7\u6ce8\u5165 CSS \u7684\u65b9\u5f0f\u8ba9\u5e7f\u544a\u5bb9\u5668\u9690\u85cf\uff0c\u5176\u76f8\u5173\u4ee3\u7801\u4f1a\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/2022-05-22_211908.png\" width=\"545\" height=\"256\" alt=\"\u6ce8\u5165\u7684\u6837\u5f0f\u8868\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u8fd9\u4e9b\u91cc\u7684 <code>display: none<\/code> \u9690\u85cf\u5f00\u53d1\u4eba\u5458\u662f\u65e0\u8bba\u5982\u4f55\u4e5f\u65e0\u6cd5\u91cd\u7f6e\u7684\uff0c\u88ab\u7ea7\u8054\u89c4\u5219\u7ed9\u9650\u5236\u4e86\u3002<\/p>\n<h3>\u4e09\u3001\u5b8c\u6574\u7684\u6837\u5f0f\u4f18\u5148\u7ea7<\/h3>\n<p>\u4e00\u4e2a CSS \u6837\u5f0f\u662f\u5426\u751f\u6548\uff0c\u5176\u4f18\u5148\u7ea7\u662f\u7531\u4e0b\u9762\u8fd9\u4e09\u53e5\u8bdd\u51b3\u5b9a\u7684\u3002<\/p>\n<p>\u8fd9\u4e09\u53e5\u8bdd\u5f88\u91cd\u8981\uff0c\u5927\u5bb6\u53ef\u4ee5\u62ff\u5c0f\u672c\u672c\u8bb0\u4e00\u4e0b\u3002<\/p>\n<p><strong>1. \u7ee7\u627f\u662f\u6700\u5e95\u5c42\uff0c\u4f4e\u4e8e\u6240\u6709\u7684\u7ea7\u8054\u89c4\u5219\u3002<\/strong><br \/>\n<strong>2. \u7ea7\u8054\u89c4\u5219\u65e0\u6cd5\u8de8\u8d8a\uff0c\u9664\u975e\u4f7f\u7528 !important \u9006\u88ad\u3002<\/strong><br \/>\n<strong>3. \u540c\u4e00\u7ea7\u8054\u89c4\u5219\u5185\u7684\u4f18\u5148\u7ea7\u6309\u7167\u9009\u62e9\u5668\u6743\u91cd\u548c\u5148\u540e\u987a\u5e8f\u51b3\u5b9a\u3002<\/strong><\/p>\n<p>\u7528\u4e00\u5f20\u56fe\u8868\u793a\u5c31\u662f\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/css-important-s.png\" width=\"720\" height=\"756\" alt=\"\u4f18\u5148\u7ea7\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u672c\u4eba\u4f7f\u7528figma\u8f9b\u82e6\u7ed8\u5236\u7684\u3002<\/p>\n<p>\u5982\u679c\u6709\u4eba\u56e0\u4e3a\u67d0\u4e9b\u539f\u56e0\u9700\u8981\u539f\u59cb\u9ad8\u6e05\u65e0\u6c34\u5370\u5927\u56fe\uff082592*2624\uff09\uff0c\u53ef\u4ee5\u52a0\u6211\u5fae\u4fe1 zhangxinxu-job \u4e94\u5143\u8d2d\u4e70\u4e4b\u3002<\/p>\n<h3>\u56db\u3001\u7ed3\u8bed\u5566~<\/h3>\n<p>\u624e\u5b9e\u7684\u57fa\u7840\u77e5\u8bc6\u6709\u52a9\u4e8e\u6211\u4eec\u770b\u5230\u67d0\u4e9b\u770b\u4f3c\u666e\u901a\u4f46\u4e0d\u89e3\u7684\u80cc\u540e\u73b0\u8c61\u7684\u539f\u56e0\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4e3a\u4f55\u6d4f\u89c8\u5668\u5185\u7f6e\u7684\u8f93\u5165\u6846\u6837\u5f0f\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u91cd\u7f6e\uff0c\u4f46\u662f\u8bbe\u7f6e\u4e86 !important \u7684\u6d4f\u89c8\u5668\u5185\u7f6e\u6837\u5f0f\u4e3a\u4f55\u91cd\u7f6e\u65e0\u6548\u5462\uff1f<\/p>\n<p>\u5982\u679c\u4f60\u4e86\u89e3 CSS \u4e2d\u7684\u7ea7\u8054\u89c4\u5219\uff0c\u5c31\u80fd\u4e00\u4e0b\u5b50\u641e\u6e05\u695a\u5176\u4e2d\u7684\u95e8\u9053\u4e86\u3002<\/p>\n<p>\u800c\u5e73\u5e38\u6211\u4eec\u5f00\u53d1\uff0c\u90fd\u662f\u5728\u201c\u5f00\u53d1\u8005\u6837\u5f0f\u8bbe\u7f6e\u201d\u8fd9\u4e2a\u7ea7\u8054\u89c4\u5219\u4e0b\u8fdb\u884c\u7684\uff0c\u57fa\u672c\u4e0a\u5168\u90fd\u5728\u8fd9\u4e2a\u5c0f\u4e16\u754c\u4e2d\u8fd0\u884c\uff0c\u56e0\u6b64\uff0c\u5927\u5bb6\u90fd\u5b89\u597d\uff0c\u4e0d\u61c2\u7ea7\u8054\u89c4\u5219\u4e5f\u6ca1\u4ec0\u4e48\u5927\u4e0d\u4e86\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u968f\u7740 <code>@layer<\/code> \u89c4\u5219\u7684\u51fa\u73b0\uff0c\u76f8\u5f53\u4e8e\u5728\u201c\u5f00\u53d1\u8005\u6837\u5f0f\u8bbe\u7f6e\u201d\u8fd9\u4e2a\u7ea7\u8054\u89c4\u5219\u5185\u53c8\u5f00\u7bc7\u4e86\u4e00\u4e2a\u65b0\u7684\u7ea7\u8054\u89c4\u5219\uff0c\u6b64\u65f6\u518d\u4e0d\u4e86\u89e3\u8fd9\u4e2a\u57fa\u7840\u77e5\u8bc6\uff0c\u5b66\u4e60\u548c\u7406\u89e3\u6050\u6015\u5c31\u4e0d\u4e00\u5b9a\u8ddf\u5f97\u4e0a\u4e86\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u65e0\u8bba\u54ea\u95e8\u8bed\u8a00\u7684\u5b66\u4e60\uff0c\u57fa\u7840\u548c\u4f53\u7cfb\u90fd\u662f\u6781\u4e3a\u91cd\u8981\u7684\u3002<\/p>\n<p>\u597d\u5566\uff0c\u5c31\u8bf4\u8fd9\u4e48\u591a\uff0c\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u53ef\u4ee5\u5e2e\u52a9\u5230\u5927\u5bb6\u7684\u5b66\u4e60\u3002<\/p>\n<p>\u5982\u679c\u89c9\u5f97\u5185\u5bb9\u4e0d\u9519\uff0c\u6b22\u8fce<button onclick=\"shareWeixin.click()\" class=\"entry-share-btn\">\u5206\u4eab<\/button>\u54e6\uff0c\u6bd4\u5fc3\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2764.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10412\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10412<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202205\/css-cover.png\" width=\"160\" height=\"102\" alt=\"CSS\u7ea7\u8054\u5c01\u9762\u56fe\" class=\"alignright size-medium\" \/><\/p>\n<p>CSS\u4e2d\u6709\u4e24\u4e2a\u91cd\u8981\u7684\u57fa\u7840\u89c4\u5219\uff0c\u4e00\u4e2a\u662f\u7ea7\u8054\uff08Cascading\uff09\uff0c\u4e00\u4e2a\u662f\u7ee7\u627f\uff08Inheritance\uff09\uff0c\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u7ea7\u8054\u89c4\u5219\uff0c\u7406\u89e3\u4e86\u7ea7\u8054\uff0c\u5c31\u80fd\u660e\u767d\u67d0\u4e9b\u770b\u4f3c\u666e\u901a\u4f46\u4e0d\u89e3\u7684\u80cc\u540e\u73b0\u8c61\u7684\u539f\u56e0\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1833,1015,1012,1832,1271,980,1831,331,449,212],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10412"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=10412"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10412\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}