{"id":10535,"date":"2022-09-20T23:10:45","date_gmt":"2022-09-20T15:10:45","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10535"},"modified":"2022-09-22T14:48:15","modified_gmt":"2022-09-22T06:48:15","slug":"css-is-where-scoped-style","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2022\/09\/css-is-where-scoped-style\/","title":{"rendered":"\u5de7\u7528:is()\u6216:where()\u4f2a\u7c7b\u8ba9scoped\u7684style\u4f9d\u7136\u5168\u5c40\u5339\u914d"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10535\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10535<\/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\/202209-is-where.jpg';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/cover-is-where.jpg\" width=\"480\" height=\"305\" alt=\"\u718a\u548c\u5154\u5b50\uff0c\u5c01\u9762\u56fe\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<h3>\u4e00\u3001\u5f15\u8a00<\/h3>\n<p>\u5728Vue\u6216React\u7b49\u524d\u7aef\u6846\u67b6\u4e2d\uff0c\u5176\u7ec4\u4ef6\u6a21\u5757\u4e3a\u4e86\u4fdd\u8bc1\u6837\u5f0f\u7684\u552f\u4e00\u6027\uff0c\u4e5f\u5c31\u662f\u62e5\u6709\u81ea\u5df1\u72ec\u7acb\u7684CSS\u4f5c\u7528\u57df\uff0c\u4f1a\u4f7f\u7528<code>&lt;style scoped&gt;<\/code>\u8fd9\u4e2a\u8bed\u6cd5\uff0c<code>scoped<\/code>\u5c5e\u6027\u662fChrome\u6d4f\u89c8\u5668\u66fe\u7ecf\u6619\u82b1\u4e00\u73b0\u652f\u6301\u8fc7\u7684\u5c5e\u6027\uff0c\u53ef\u4ee5\u5b9e\u73b0CSS\u4f5c\u7528\u57df\u6548\u679c\uff0c\u540e\u6765\u5e9f\u5f03\u4e86\u3002<\/p>\n<p>\u73b0\u5728\u88ab\u6846\u67b6\u4f7f\u7528\uff0c\u7528\u6765\u8868\u793a\u8fd9\u6bb5CSS\u662f\u6a21\u5757\u5185\u79c1\u6709\u7684\u3002<\/p>\n<p>\u53ef\u6d4f\u89c8\u5668\u5e76\u4e0d\u652f\u6301\u8fd9\u4e2a\u5c5e\u6027\uff0c\u90a3\u6846\u67b6\u662f\u5982\u4f55\u5b9e\u73b0CSS\u4f5c\u7528\u57df\u529f\u80fd\u7684\u5462\uff1f<\/p>\n<p>\u65b9\u6cd5\u662f\u7ed9\u8bbe\u7f6e\u4e86scoped\u5c5e\u6027\u7684<code>&lt;style&gt;<\/code>\u5143\u7d20\u5185\u7684CSS\u9009\u62e9\u5668\u6dfb\u52a0\u968f\u673a\u7684\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u7136\u540e\u6a21\u5757\u5185\u6a21\u677fHTML\u4e5f\u90fd\u589e\u52a0\u540c\u6837\u540d\u79f0\u7684\u5c5e\u6027\u540d\u79f0\uff0c\u4e8e\u662f\u5c31\u80fd\u5339\u914d\u4e0a\u4e86\u3002<\/p>\n<p>\u5982\u4e0b\u56fe\u793a\u610f\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/random-attr-min.png\" width=\"470\" height=\"294\" alt=\"\u968f\u673a\u5c5e\u6027\u4e0e\u5bf9\u5e94\u7684\u5c5e\u6027\u9009\u62e9\u5668\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u8fd9\u756a\u64cd\u4f5c\u662f\u6ca1\u6709\u4efb\u4f55\u95ee\u9898\u7684\u3002<\/p>\n<p>\u53ef\u6709\u65f6\u5019\uff0c\u9875\u9762\u4e2d\u7684DOM\u5143\u7d20\u5e76\u975e\u73b0\u6210\u7684\uff0c\u800c\u662f\u52a8\u6001\u751f\u6210\u7684\uff0c\u8fd9\u4e2a\u65f6\u5019\uff0c\u6846\u67b6\u5c31\u65e0\u6cd5\u6dfb\u52a0\u968f\u673a\u5c5e\u6027\u3002<\/p>\n<p>\u8fd9\u79cd\u573a\u666f\u591a\u51fa\u73b0\u5728\u7b2c\u4e09\u65b9\u7ec4\u4ef6\uff0c\u6216\u8005\u9700\u8981\u76f4\u63a5\u9762\u5411DOM\u5904\u7406\u7684\u5f00\u53d1\u573a\u666f\u3002<\/p>\n<p>\u4f8b\u5982\u6709\u5982\u4e0b\u9700\u6c42\uff0c\u5e0c\u671b\u91cd\u7f6e\u67d0\u7b2c\u4e09\u65b9\u7ec4\u4ef6\u5355\u9009\u6846\u7684\u989c\u8272\u4e3a\u5404\u79cd\u72b6\u6001\u8272\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/colorfull-radio-min.png\" width=\"66\" height=\"86\" alt=\"\u5f69\u8272\u5355\u9009\u6309\u94ae\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6211\u4eec\u6253\u5f00\u63a7\u5236\u53f0\u67e5\u770b\u5bf9\u5e94\u7684HTML\u7ed3\u6784\uff0c\u4f1a\u53d1\u73b0\u7ed8\u5236\u8fb9\u6846\u7684\u8fd9\u4e2a\u5143\u7d20\u4e0a\u5e76\u6ca1\u6709\u4efb\u4f55\u968f\u673a\u5c5e\u6027\uff0c\u662f\u5e72\u5e72\u51c0\u51c0\u7684\u539f\u59cb\u7684HTML\u5185\u5bb9\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/ele-no-attr-min.png\" width=\"335\" height=\"206\" alt=\"\u5e72\u51c0\u7684DOM\u7ed3\u6784\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5982\u679c\u5e0c\u671b\u5bf9\u8fd9\u4e2a<code>.ant-radio-inner<\/code>\u5143\u7d20\u8fdb\u884c\u6837\u5f0f\u91cd\u7f6e\uff0c\u5219\u5199\u5728scoped\u8303\u56f4\u5185\u5c31\u65e0\u6548\u3002<\/p>\n<pre>&lt;style scoped&gt;\r\n\/* \u65e0\u6cd5\u91cd\u7f6e *\/\r\n.status-normal .ant-radio-inner {\r\n  --color: var(--blue6);\r\n}\r\n&lt;\/style&gt;<\/pre>\n<p>\u56e0\u4e3a\u6846\u67b6\u5728\u7f16\u8bd1\u540e\uff0c\u4f1a\u7ed9<code>.ant-radio-inner<\/code>\u8fd9\u4e2a\u7c7b\u540d\u7c7b\u540d\u518d\u589e\u52a0\u4e00\u4e2a\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u5bfc\u81f4\u65e0\u6cd5\u548cDOM\u4e2d\u7684\u5143\u7d20\u5339\u914d\u4e0a\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/add-rand-attr-min.png\" width=\"448\" height=\"217\" alt=\"\u589e\u52a0\u4e86\u5c5e\u6027\u9009\u62e9\u5668\u800c\u65e0\u6cd5\u5339\u914d\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6211\u4eec\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u52a8\u6001\u63d2\u5165\u7684HTML\uff0c\u6216\u8005\u7ed5\u5f00\u6846\u67b6\u8fdb\u884c\u7684\u76841v1 DOM\u64cd\u4f5c\u90fd\u4f1a\u9047\u5230\u7c7b\u4f3c\u7684\u95ee\u9898\u3002<\/p>\n<p>\u76ee\u524d\uff0c\u5927\u5bb6\u666e\u901a\u7684\u505a\u6cd5\u662f\u628a\u8fd9\u4e9bCSS\u4ee3\u7801\u5199\u5728\u5168\u5c40\u7684CSS\u4e0a\u4e0b\u6587\u4e2d\u3002<\/p>\n<p>\u4f8b\u5982\u5168\u7ad9\u516c\u7528\u7684style.css\u6587\u4ef6\uff0c\u6216\u8005\u8fd8\u5728\u8fd9\u4e2a\u7ec4\u4ef6\u6587\u4ef6\u4e2d\uff0c\u4f46\u662f\u662f\u5199\u5728\u4e0d\u542bscoped\u5c5e\u6027\u7684<code>&lt;style&gt;<\/code>\u5143\u7d20\u4e2d\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;style&gt;\r\n\/* \u53ef\u4ee5\u91cd\u7f6e *\/\r\n.status-normal .ant-radio-inner {\r\n  --color: var(--blue6);\r\n}\r\n&lt;\/style&gt;<\/pre>\n<p>\u4f46\u8fd9\u79cd\u505a\u6cd5\u5e76\u4e0d\u5b8c\u7f8e\uff0c\u56e0\u4e3a\u672c\u6765\u5e94\u8be5\u5728\u4e00\u8d77\u7684CSS\u4ee3\u7801\u5757\u88ab\u8feb\u5206\u79bb\u5230\u4e86\u4e24\u4e2a\u5730\u65b9\uff0c\u5bf9\u4e8e\u65e5\u540e\u7684\u7ef4\u62a4\u5e26\u6765\u8bf8\u591a\u4e0d\u53d8\u3002<\/p>\n<p>\u90a3\u6709\u6ca1\u6709\u4ec0\u4e48\u529e\u6cd5\uff0c\u5373\u5199\u5728scoped\u73af\u5883\u4e2d\uff0c\u53c8\u4e0d\u4f1a\u589e\u52a0\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u4ece\u800c\u53ef\u4ee5\u5339\u914d\u7b2c\u4e09\u65b9\u7ec4\u4ef6DOM\u7ed3\u6784\u5462\uff1f<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/stand.jpeg\" width=\"300\" height=\"169\" alt=\"\u7ad9\u7740\u6323\u94b1\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6709\uff01<\/p>\n<p>\u4e00\u79cd\u662f\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684 <code>:deep()<\/code> \u4f2a\u7c7b\u51fd\u6570\uff08\u53ea\u80fd\u662fVue\u5f00\u53d1\u73af\u5883\uff0cReact\u4f7f\u7528 :global()\uff09\uff1a<\/p>\n<pre>.a :deep(.b) { \/* ... *\/ }<\/pre>\n<p>\u8fd8\u6709\u4e00\u79cd\u66f4\u52a0\u539f\u751f\uff0c\u9002\u7528\u573a\u666f\u66f4\u5e7f\u6cdb\u7684\u65b9\u6cd5\uff0c\u5c31\u662f\u4f7f\u7528<code>:is()<\/code>\u6216<code>:where()<\/code>\u4f2a\u7c7b\u3002<\/p>\n<h3>\u4e8c\u3001\u5feb\u901f\u4e86\u89e3:is\u548c:where\u4f2a\u7c7b<\/h3>\n<p><code>:is()<\/code>\u4f2a\u7c7b\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u79cdCSS\u4e66\u5199\u8bed\u6cd5\u7cd6\uff0c\u53ef\u4ee5\u7b80\u5316\u590d\u6742\u4e14\u91cd\u590d\u9009\u62e9\u5668\u7684\u4e66\u5199\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>.active > .class-a,\r\n.active > .class-b,\r\n.active > .class-c {\r\n  display: block;\r\n}<\/pre>\n<p>\u53ef\u4ee5\u7b80\u5316\u6210\uff1a<\/p>\n<pre>active > :is(.class-a, .class-b, .class-c) {\r\n  display: block;\r\n}<\/pre>\n<p>\u800c<code>:where()<\/code>\u4f2a\u7c7b\u548c<code>:is()<\/code>\u4f2a\u7c7b\u7684\u8bed\u6cd5\u3001\u4f5c\u7528\u4e00\u6a21\u4e00\u6837\uff0c\u533a\u522b\u5728\u4e8e\u9009\u62e9\u5668\u7684\u4f18\u5148\u7ea7\u4e0a\u3002<\/p>\n<p><code>:where()<\/code>\u4f2a\u7c7b\u7684\u4f18\u5148\u7ea7\u662f0\uff0c\u65e0\u8bba\u5176\u53c2\u6570\u5185\u7684\u9009\u62e9\u5668\u4f18\u5148\u7ea7\u591a\u9ad8\uff0c\u662f\u6574\u4e2aCSS\u4e16\u754c\u4e2d\u4e3a\u6570\u4e0d\u591a\u7684\u53ef\u4ee5\u964d\u4f4e\u9009\u62e9\u5668\u4f18\u5148\u7ea7\u7684\u7279\u6027\uff08\u53e6\u5916\u4e00\u4e2a\u662f @layer \u89c4\u5219\uff0c\u8be6\u89c1\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2022\/05\/css-layer-rule\/\">\u8be6\u89e3\u65e5\u540e\u5b9a\u4f1a\u5927\u89c4\u6a21\u4f7f\u7528\u7684CSS @layer \u89c4\u5219<\/a>\u201d\u4e00\u6587\uff09\u3002<\/p>\n<p>\u800c<code>:is()<\/code>\u4f2a\u7c7b\u7684\u4f18\u5148\u7ea7\u662f\u7531\u62ec\u53f7\u5185\u9009\u62e9\u5668\u7684\u4f18\u5148\u7ea7\u51b3\u5b9a\u7684\uff0c\u4ece\u8fd9\u4e00\u70b9\u6765\u770b\uff0c<code>:where()<\/code>\u4f2a\u7c7b\u7684\u4f5c\u7528\u53ef\u80fd\u8fd8\u66f4\u5927\u4e00\u70b9\u3002<\/p>\n<p>\u626f\u8fdc\u4e86\u3002<\/p>\n<p>\u5982\u679c\u5355\u770b<code>:is()<\/code>\u4f2a\u7c7b\u7684\u4f5c\u7528\uff0c\u4f3c\u4e4e\u5e76\u4e0d\u80fd\u8ba9\u6211\u4eec\u5174\u594b\uff0c\u6bd5\u7adf\u9009\u62e9\u5668\u7b80\u5316\u2026\u2026\u6069\u2026\u2026\u4e5f\u4e0d\u662f\u4ec0\u4e48\u5f3a\u70c8\u7684\u9700\u6c42\uff0c\u6709\u4eba\u8bf4\u4e0d\u5b9a\u5c31\u559c\u6b22\u5206\u5f00\u5199\uff1a\u77a7\uff0c\u6d0b\u6d0b\u6d12\u6d12\uff0c\u4e00\u5bb6\u4eba\u6574\u6574\u9f50\u9f50\uff0c\u4e0d\u633a\u597d\u7684\uff01<\/p>\n<p>\u4f46\uff0c\u5982\u679c\u6211\u544a\u8bc9\u4f60\uff0c\u5728Vue\u7b49\u6846\u67b6\u4e2d\u4f7f\u7528<code>:is()<\/code>\u4f2a\u7c7b\uff0c\u9009\u62e9\u5668\u5c31\u4e0d\u4f1a\u518d\u589e\u52a0\u968f\u673a\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u4f60\u4f1a\u600e\u4e48\u60f3\u5462\uff1f<\/p>\n<p>\u8fd8\u662f\u56de\u5230\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u540c\u6837\u5728scoped\u6837\u5f0f\u4e2d\uff0c\u73b0\u5728\uff0c\u6211\u4eec\u628a\u9700\u8981\u91cd\u7f6e\u7684\u7c7b\u540d\u9009\u62e9\u5668\u4f7f\u7528:is()\u5305\u88f9\u4e0b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>&lt;style scoped&gt;\r\n\/* \u53ef\u4ee5\u91cd\u7f6e *\/\r\n.status-normal :is(.ant-radio-inner) {\r\n  --color: var(--blue6);\r\n}\r\n&lt;\/style&gt;<\/pre>\n<p>\u795e\u5947\u7684\u4e8b\u60c5\u53d1\u751f\u4e86\uff01<\/p>\n<p>\u6210\u529f\u91cd\u7f6e\u4e86\u7b2c\u4e09\u65b9\u7ec4\u4ef6\u7684\u6837\u5f0f\uff0c\u6b64\u65f6\u7f16\u8bd1\u51fa\u6765\u7684CSS\u9009\u62e9\u5668\u662f\u8fd9\u6837\u5b50\u7684\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/is-code-min.png\" width=\"444\" height=\"83\" alt=\"\u544a\u522b\u968f\u673a\u9009\u62e9\u5668\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5c31\u53ef\u4ee5\u628a\u7b2c\u4e09\u65b9\u7ec4\u4ef6\u7684CSS\u7ed9\u91cd\u7f6e\u6389\u4e86\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/shine-eye.jpeg\" width=\"150\" height=\"84\" alt=\"\u773c\u775b\u653e\u5149\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u6211\u4eec\u7684\u4ee3\u7801\u518d\u4e5f\u4e0d\u9700\u8981\u9aa8\u8089\u5206\u79bb\uff0c\u5199\u5728\u4e24\u5904\u4e86\uff01<\/p>\n<p><strong>\u517c\u5bb9\u6027<\/strong><\/p>\n<p><code>:is()<\/code>\u4f2a\u7c7b\u6b63\u5f0f\u652f\u6301\u662fChrome88\u5f00\u59cb\u7684\uff0c\u4e5f\u5c31\u662f21\u5e741\u6708\u4efd\uff0c\u5230\u73b0\u5728\u5df2\u7ecf\u5feb2\u5e74\u4e86\uff0c\u90a3\u4e9b\u5bf9\u517c\u5bb9\u6027\u8981\u6c42\u4e0d\u9ad8\u7684\u9879\u76ee\u53ef\u4ee5\u653e\u5fc3\u5927\u80c6\u4f7f\u7528\uff0c\u5982\u679c\u975e\u8981\u517c\u5bb9\u9648\u65e7\u6d4f\u89c8\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>:-webkit-any()<\/code> \u4f2a\u7c7b\u517c\u5bb9\u4e0b\uff0c\u9664\u4e86\u9009\u62e9\u5668\u7684\u4f18\u5148\u7ea7\u4e0d\u4e00\u6837\u5916\uff08:any()\u4f2a\u7c7b\u7684\u4f18\u5148\u7ea7\u6052\u5b9a\u4e3a\u7c7b\u9009\u62e9\u5668\u4f18\u5148\u7ea7\uff0c\u5ffd\u7565\u91cc\u9762\u7684\u53c2\u6570\uff09\uff0c\u5176\u4ed6\u529f\u6548\u662f\u4e00\u6837\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;style scoped&gt;\r\n\/* \u4e5f\u53ef\u4ee5\u91cd\u7f6e *\/\r\n.status-normal :-webkit-any(.ant-radio-inner) {\r\n  --color: var(--blue6);\r\n}\r\n&lt;\/style&gt;<\/pre>\n<p>\u622a\u56fe\u793a\u610f\u5982\u4e0b\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/any-code-min.png\" width=\"481\" height=\"100\" alt=\"-webkit-any\u4f5c\u7528\" class=\"alignnone size-medium\" \/><\/p>\n<p><small class=\"hidden\">\/\/zxx: \u5982\u679c\u4f60\u770b\u5230\u8fd9\u6bb5\u6587\u5b57\uff0c\u8bf4\u660e\u4f60\u73b0\u5728\u8bbf\u95ee\u662f\u4e0d\u662f\u539f\u6587\u7ad9\u70b9\uff0c\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u5728\u8fd9\u91cc\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/?p=10535\uff08\u4f5c\u8005\u5f20\u946b\u65ed\uff09<\/small><\/p>\n<p>\u517c\u5bb9\u6027\u5982\u4e0b\uff0c\u53ef\u4ee5\u770b\u5230<code>:any()<\/code>\u4f2a\u7c7b\u5f88\u65e9\u5f88\u65e9\u5c31\u652f\u6301\u4e86\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/2022-09-20_230621.png\" width=\"651\" height=\"340\" alt=\":any()\u7684\u517c\u5bb9\u6027\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e09\u3001\u540c\u6837\u662f\u903b\u8f91\u4f2a\u7c7b\u7684:not\u5462\uff1f<\/h3>\n<p>\u4ece\u6280\u672f\u89d2\u5ea6\u8bb2\uff0c<code>:not()<\/code>\u4f2a\u7c7b\u4e5f\u53ef\u4ee5\u4fdd\u62a4\u57fa\u672c\u9009\u62e9\u5668\u4e0d\u6dfb\u52a0\u52a8\u6001\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u4f46\u662f\uff0c\u64cd\u4f5c\u4e0a\u5e76\u6ca1\u6709\u90a3\u4e48\u7b80\u5355\uff0c\u56e0\u4e3a:not()\u4f2a\u7c7b\u7684\u542b\u4e49\u662f\u5426\u5b9a\uff0c\u800c<code>:is()<\/code>\u7b49\u7eaf\u7cb9\u8bed\u6cd5\u4f5c\u7528\u7684\u4f2a\u7c7b\u4e0d\u540c\u3002<\/p>\n<p>\u90a3\u662f\u4e0d\u662f\u53ef\u4ee5\u4f7f\u7528\u53cc\u91cd\u5426\u5b9a\uff1f<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;style scoped&gt;\r\n.status-normal :not(:not(.ant-radio-inner)) {\r\n  --color: var(--blue6);\r\n}\r\n&lt;\/style&gt;<\/pre>\n<p>\u6ca1\u9519\uff0c\u529f\u80fd\u4e0a\u8bb2\uff0c\u662f\u53ef\u4ee5\u5339\u914d\u7684\uff01<\/p>\n<p>\u4f46\u662f\uff0c<code>:not()<\/code>\u4f2a\u7c7b\u7684\u53c2\u6570\u652f\u6301\u590d\u6742\u9009\u62e9\u5668\u4e5f\u662f<a href=\"https:\/\/caniuse.com\/?search=%3Anot\" rel=\"noopener\" target=\"_blank\">Chrome88\u624d\u652f\u6301<\/a>\u7684\uff0c\u548c<code>:is()<\/code>\u4f2a\u7c7b\u4e00\u6837\uff0c\u56e0\u800c\u5b8c\u5168\u6ca1\u6709\u4f7f\u7528<code>is()<\/code>\u4f2a\u7c7b\u7684\u7406\u7531\u3002<\/p>\n<h3>\u56db\u3001\u518d\u8bf4\u70b9\u4ec0\u4e48<\/h3>\n<p>\u6211\u4f30\u7b97\uff0c\u4efb\u610f\u7684\u4f7f\u7528\u9009\u62e9\u5668\u4f5c\u4e3a\u53c2\u6570\u7684CSS\u51fd\u6570\u90fd\u53ef\u4ee5\u5b9e\u73b0\u672c\u6587\u7684\u9700\u6c42\u3002<\/p>\n<p>\u56e0\u6b64\uff0c<code>:has()<\/code>\u4f2a\u7c7b\u80af\u5b9a\u4e5f\u662f\u53ef\u4ee5\u7684\u3002<\/p>\n<p>\u8fd9\u4e0b\uff0cCSS \u56db\u5927\u903b\u8f91\u4f2a\u7c7b\u90fd\u5230\u9f50\u4e86\uff0c\u6070\u597d\uff0c\u4e0a\u5468\u5728B\u7ad9\u5f55\u4e86\u4e2a7\u5206\u949f\u7684\u4ecb\u7ecdCSS\u903b\u8f91\u4f2a\u7c7b\u7684\u89c6\u9891\uff0c\u5927\u5bb6\u6709\u5174\u8da3\u53ef\u4ee5\u70b9\u51fb\u770b\u770b\uff0c\u8fd8\u6ca1\u5173\u6ce8\u6211B\u7ad9\u8d26\u53f7\u7684\u5c0f\u4f19\u4f34\u4e5f\u53ef\u4ee5\u5173\u6ce8\u4e0b\uff0c\u4f1a\u4e0d\u5b9a\u671f\u53d1\u5e03\u524d\u7aef\u6280\u672f\u89c6\u9891\u3002<\/p>\n<p><iframe id=\"biliFrame\" src=\"\/\/player.bilibili.com\/player.html?aid=857937485&#038;bvid=BV17V4y1g7Bj&#038;cid=831284030&#038;page=1\" scrolling=\"no\" border=\"0\" frameborder=\"no\" framespacing=\"0\" allowfullscreen=\"true\" width=\"100%\"> <\/iframe><br \/>\n<script>\n(function() {\nvar eleFrame = document.getElementById('biliFrame');\nif (eleFrame) {\neleFrame.setAttribute('height', eleFrame.clientWidth * 3 \/ 4.5);\n}\n})();\n<\/script><\/p>\n<p>\u53e6\u5916\uff0c\u8bf4\u4e00\u70b9\uff0c\u6709\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u6574\u4e2aCSS\u9009\u62e9\u5668\u90fd\u4e0d\u9700\u8981\u589e\u52a0\u52a8\u6001\u7684\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u901a\u914d\u7b26\u5904\u7406\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;style scoped&gt;\r\n* > :is(.status-normal) :is(.ant-radio-inner) {\r\n  --color: var(--blue6);\r\n}\r\n&lt;\/style&gt;<\/pre>\n<p>\u6b64\u65f6\uff0c\u968f\u673a\u5c5e\u6027\u503c\u4f1a\u52a0\u8f7d\u901a\u914d\u7b26\u4e0a\uff0c\u81ea\u7136\u65e2\u4fdd\u8bc1\u4e86\u5c40\u90e8\u79c1\u6709\uff0c\u53c8\u4e0d\u8981\u62c5\u5fc3\u65e0\u6cd5\u91cd\u7f6e\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5728\u6846\u67b6\u5f00\u53d1\u76db\u884c\u7684\u4eca\u65e5\uff0c\u672c\u6587\u7684\u5c0f\u6280\u5de7\u80af\u5b9a\u5f88\u53d7\u7528\u7684\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f60f.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=10535\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10535<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202209\/cover-is-where.jpg\" width=\"160\" height=\"102\" alt=\"\u718a\u548c\u5154\u5b50\u5c01\u9762\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e00\u4e2a\u5b9e\u7528\u524d\u7aef\u6280\u672f\uff0c\u53ef\u4ee5\u8ba9\u6846\u67b6\u4e2d\u79c1\u6709\u4e0a\u4e0b\u6587\u4e2d\u7684CSS\u4e0d\u6dfb\u52a0\u968f\u673a\u5c5e\u6027\u9009\u62e9\u5668\uff0c\u4ece\u800c\u53ef\u4ee5\u5339\u914d\u7b2c\u4e09\u65b9\u7ec4\u4ef6\u7684HTML\u7ed3\u6784\u4ee5\u53caJS\u52a8\u6001\u751f\u6210\u7684HTML\u5143\u7d20\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":[1850,1459,865,1024,1460,1857,1689,843,864,353,212],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10535"}],"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=10535"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10535\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}