{"id":8808,"date":"2019-07-28T19:05:59","date_gmt":"2019-07-28T11:05:59","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=8808"},"modified":"2019-07-28T19:08:18","modified_gmt":"2019-07-28T11:08:18","slug":"css-not-pseudo-class","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2019\/07\/css-not-pseudo-class\/","title":{"rendered":"CSS :not\u4f2a\u7c7b\u53ef\u80fd\u9519\u8bef\u7684\u8ba4\u8bc6"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=8808\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=8808<\/a><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<br \/>\n<script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/201907-css-not.jpg';<\/script><\/p>\n<h3>\u4e00\u3001\u7279\u522b\u7684\u4f60\uff0c\u7279\u522b\u76840\u4f18\u5148\u7ea7<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201907\/not-cover.jpg\" width=\"242\" height=\"150\" alt=\"\u4e0d\u6562\u76f8\u4fe1\" class=\"alignright thumb size-medium\" \/> <strong>CSS :not\u4f2a\u7c7b\u5e38\u89c1\u9519\u8bef\u8ba4\u77e5\u4e4b\u4e00\u5c31\u662f\u641e\u4e0d\u6e05\u695a\u5176\u4f18\u5148\u7ea7\u3002<\/strong><\/p>\n<p>\u5982\u679c\u5bf9\u6240\u6709CSS\u4f2a\u7c7b\u7684\u4f18\u5148\u7ea7\uff08\u4e5f\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684\u9009\u62e9\u5668\u6743\u91cd\uff09\u8fdb\u884c\u5206\u7c7b\uff0c\u4f60\u4f1a\u53d1\u73b0\u603b\u5171\u53ea\u6709\u4e24\u4e2a\u7ea7\u522b\uff0c<code>0<\/code>\u7ea7\u548c<code>10<\/code>\u7ea7<sup>\u2460<\/sup>\u3002<\/p>\n<blockquote><p>\u2460 0\u7ea7\u6307\u6ca1\u6709\u4f18\u5148\u7ea7\uff0c1\u7ea7\u662f\u6807\u7b7e\u9009\u62e9\u5668\uff0c10\u7ea7\u662f\u7c7b\u9009\u62e9\u5668\uff0c\u5c5e\u6027\u9009\u62e9\u5668\uff0c100\u7ea7\u662fID\u9009\u62e9\u5668\u3002<\/p><\/blockquote>\n<p>\u4f2a\u7c7b\uff0c\u4f2a\u7c7b\uff0c\u65e2\u7136\u5e26\u6709\u201c\u7c7b\u201d\u5b57\uff0c\u81ea\u7136\u5176\u4f18\u5148\u7ea7\u597d\u7c7b\u9009\u62e9\u5668\u4e00\u81f4\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u5176\u4e2d\u6709\u4e2a\u7279\u6b8a\uff0c\u90a3\u5c31\u662f\u903b\u8f91\u4f2a\u7c7b\u7684\u4f18\u5148\u7ea7\u90fd\u662f<code>0<\/code>\u3002\u4f8b\u5982\uff1a<code>:not()<\/code>\uff0c<code>:is()<\/code>\uff0c<code>:where()<\/code>\u7b49\u3002<\/p>\n<p>\u903b\u8f91\u4f2a\u7c7b\u6574\u4e2a\u9009\u62e9\u5668\u8bed\u53e5\u7684\u4f18\u5148\u7ea7\u662f\u7531\u62ec\u53f7\u91cc\u9762\u5185\u5bb9\u51b3\u5b9a\u7684\uff0c\u4e0d\u540c\u7684\u903b\u8f91\u4f2a\u7c7b\u89c4\u5219\u4e0d\u4e00\u6837\uff0c\u5176\u4e2d<code>:not()<\/code>\u4f2a\u7c7b\u7684\u672c\u8eab\u6ca1\u6709\u4f18\u5148\u7ea7\uff0c\u6700\u7ec8\u4f18\u5148\u7ea7\u662f\u7531\u62ec\u53f7\u91cc\u9762\u7684\u9009\u62e9\u5668\u51b3\u5b9a\u7684\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>:not(.disabled) {}    <span style=\"color:green;\">\/* \u4f18\u5148\u7ea7\u7b49\u540c\u4e8e.disabled\u9009\u62e9\u5668 *\/<\/span>\r\n:not(a) {}    <span style=\"color:green;\">\/* \u4f18\u5148\u7ea7\u7b49\u540c\u4e8ea\u9009\u62e9\u5668 *\/<\/span><\/pre>\n<h3>\u4e8c\u3001\u751f\u7684\u65e9\uff0c\u4e0d\u652f\u6301\u590d\u6742\u9009\u62e9\u5668<\/h3>\n<p><code>:not()<\/code>\u903b\u8f91\u4f2a\u7c7b\u51fa\u8eab\u5f88\u65e9\uff0c\u65e9\u5230IE9\u6d4f\u89c8\u5668\u90fd\u652f\u6301\uff0c\u4e0d\u50cf\u73b0\u5728\u7684\u65b0\u51fa\u6765\u7684\u903b\u8f91\u9009\u62e9\u5668\uff0c<strong><code>:not()<\/code>\u4f2a\u7c7b\u62ec\u53f7\u91cc\u9762\u5e76\u4e0d\u652f\u6301\u590d\u6742\u7684\u9009\u62e9\u5668<\/strong>\uff08\u867d\u7136\u65b0\u7684\u89c4\u8303\u5df2\u7ecf\u8ba9\u652f\u6301\u4e86\uff0c\u76ee\u524d\u8fd8\u6ca1\u6709\u6d4f\u89c8\u5668\u8ddf\u8fdb\uff09\u3002<\/p>\n<p>\u4f8b\u5982\uff0c<code>:not()<\/code>\u4f2a\u7c7b\u62ec\u53f7\u91cc\u9762\u4e0d\u80fd\u591a\u4e2a\u9009\u62e9\u5668\uff1a<\/p>\n<pre>:not(.disabled, .read-only) {}    <span style=\"color:#cd0000;\">\/* \u65e0\u6548\uff0c\u4e0d\u652f\u6301 *\/<\/span><\/pre>\n<p>\u9700\u8981\u5199\u4f5c\uff1a<\/p>\n<pre>:not(.disabled), :not(.read-only) {}<\/pre>\n<p>\u4f8b\u5982\uff0c<code>:not()<\/code>\u4f2a\u7c7b\u62ec\u53f7\u91cc\u9762\u4e0d\u652f\u6301\u9009\u62e9\u5668\u7ea7\u8054\uff1a<\/p>\n<pre>:not(a.disabled) {}    <span style=\"color:#cd0000;\">\/* \u65e0\u6548\uff0c\u4e0d\u652f\u6301 *\/<\/span><\/pre>\n<p>\u9700\u8981\u5199\u4f5c\uff1a<\/p>\n<pre>:not(a):not(.disabled) {}<\/pre>\n<h3>\u4e09\u3001\u5bb9\u6613\u641e\u4e0d\u6e05\u695a\u7684\u5426\u5b9a\u903b\u8f91\u5173\u7cfb<\/h3>\n<p>\u8fd9\u662f\u672c\u6587\u7684\u91cd\u70b9\u3002<\/p>\n<h4>1. \u8fde\u7eed\u5426\u5b9a\u7684\u903b\u8f91\u9519\u8bef<\/h4>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u60f3\u8981\u5339\u914d\u65e2\u4e0d\u5305\u542b<code>.disabled<\/code>\u7c7b\u540d\uff0c\u53c8\u4e0d\u5305\u542b<code>.read-only<\/code>\u7c7b\u540d\u7684<code>&lt;input&gt;<\/code>\u5143\u7d20\uff0c\u6211\u4eec\u7684\u9009\u62e9\u5668\u8be5\u5982\u4f55\u4e66\u5199\uff0c\u5f88\u591a\u4eba\u4f1a\u4f7f\u7528\u4e0b\u9762\u7684CSS\u4ee3\u7801\uff1a<\/p>\n<pre>input:not(.disabled),\r\ninput:not(.read-only) {}<\/pre>\n<p>\u4e4d\u4e00\u770b\u597d\u50cf\u6ca1\u95ee\u9898\uff0c\u5b9e\u9645\u4e0a\uff0c\u4e0a\u9762\u7684\u4e66\u5199\u662f\u5927\u5927\u7684\u9519\u8bef\u3002<\/p>\n<p>\u9017\u53f7\u5206\u9694\u7684\u9009\u62e9\u5668\uff0c\u8868\u793a\u7684\u662f\u201c\u6216\u201d\u7684\u5173\u7cfb\uff0c\u800c\u4e0d\u662f\u201c\u4e0e\u201d\u7684\u5173\u7cfb\u3002\u56e0\u6b64<code>input:not(.disabled), input:not(.read-only)<\/code>\u8868\u793a\u7684\u542b\u4e49\u662f\uff1a\u4e0d\u5305\u542b<code>.disabled<\/code>\u7c7b\u540d\u7684<code>&lt;input&gt;<\/code>\u5143\u7d20\uff0c\u6216\u8005\u4e0d\u5305\u542b<code>.read-only<\/code>\u7c7b\u540d\u7684<code>&lt;input&gt;<\/code>\u5143\u7d20\u3002<\/p>\n<p>\u6700\u540e\u5bfc\u81f4\u7684\u7ed3\u679c\u662f<code>.disabled<\/code>\u7c7b\u540d\u548c<code>.read-only<\/code>\u7c7b\u540d\u5143\u7d20\u90fd\u4f1a\u5339\u914d\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><span style=\"color:green;\">&lt;!-- \u5747\u4f1a\u5339\u914d --&gt;<\/span>\r\n&lt;input class=\"disabled\"&gt;\r\n&lt;input class=\"read-only\"&gt;<\/pre>\n<p>\u56e0\u4e3a<code>&lt;input class=\"disabled\"&gt;<\/code>\u867d\u7136\u4e0d\u4f1a\u5339\u914dinput:not(.disabled)\uff0c\u4f46\u662f\u4f1a\u5339\u914d<code>input:not(.read-only)<\/code>\uff0c\u5bfc\u81f4\u51fa\u73b0\u4e86\u4e0d\u5e0c\u671b\u51fa\u73b0\u7684\u5339\u914d\u6548\u679c\u3002<\/p>\n<p>\u8fd9\u91cc\uff0c\u6b63\u786e\u7684\u4e66\u5199\u65b9\u6cd5\u5e94\u8be5\u662f\uff1a<\/p>\n<pre><span style=\"color:green;\">\/* \u6b63\u786e\u7684\u4e66\u5199 *\/<\/span>\r\ninput:not(.disabled):not(.read-only) {}<\/pre>\n<h4>2. \u5168\u5c40\u5426\u5b9a\u7684\u903b\u8f91\u9519\u8bef<\/h4>\n<p>\u4f8b\u5982\u6211\u4eec\u5e0c\u671b\u9664\u4e86<code>&lt;article&gt;<\/code>\u6807\u7b7e\u4e0b\u7684<code>&lt;p&gt;<\/code>\u5143\u7d20\u7684<code>margin<\/code>\u503c\u90fd\u662f<code>0<\/code>\uff0c\u6211\u4eec\u4ee3\u7801\u8be5\u600e\u4e48\u5199\u3002<\/p>\n<p>\u5f88\u591a\u4eba\u4f1a\u8fd9\u6837\u4e66\u5199\uff1a<\/p>\n<pre>:not(article) p {\r\n    margin: 0;\r\n}<\/pre>\n<p>\u770b\u4e0a\u53bb\u6ca1\u6709\u95ee\u9898\uff0c\u5b9e\u9645\u4e0a\u95ee\u9898\u975e\u5e38\u4e25\u91cd\uff0c<code>:not(article) p<\/code>\u5b9e\u9645\u8bed\u4e49\u662f\uff0c\u5982\u679c<code>&lt;p&gt;<\/code>\u5143\u7d20\u7684\u7956\u5148\u5143\u7d20\u7684\u6807\u7b7e\u540d\u4e0d\u662f<code>article<\/code>\uff0c\u5219<code>margin<\/code>\u503c\u662f<code>0<\/code>\u3002<\/p>\n<p>\u5176\u4e2d\u5c31\u5305\u62ec\u8fd9\u6837\u7684\u573a\u666f\uff1a<\/p>\n<pre>&lt;article&gt;\r\n    &lt;section&gt;\r\n        &lt;p&gt;margin\u6b64\u65f6\u4e5f\u662f0\uff01&lt;p&gt;\r\n    &lt;\/section&gt;\r\n&lt;\/article&gt;<\/pre>\n<p>\u6b64\u65f6\uff0c\u867d\u7136<code>&lt;p&gt;<\/code>\u5143\u7d20\u5728<code>&lt;article&gt;<\/code>\u5143\u7d20\u5185\uff0c\u4f46\u662f\uff0c\u7531\u4e8e\u540c\u65f6\u4e5f\u5728<code>&lt;section&gt;<\/code>\u5143\u7d20\u5185\uff0c\u4e8e\u662f\u5339\u914d\u4e86<code>:not(article) p<\/code>\u8fd9\u4e2a\u9009\u62e9\u5668\uff0c\u5bfc\u81f4\u51fa\u73b0\u610f\u6599\u4e4b\u5916\u7684\u6837\u5f0f\u8868\u73b0\u3002<\/p>\n<p>\u6b63\u786e\u7684\u4e66\u5199\u5e94\u8be5\u662f\uff1a<\/p>\n<pre>p {\r\n    margin: 0;\r\n}\r\narticle p {\r\n    margin: 1em 0;\r\n}<\/pre>\n<p>\u54a6\uff1f\u4e0d\u80fd\u4f7f\u7528<code>:not<\/code>\u4f2a\u7c7b\u5b9e\u73b0\u5417\uff1f\u5bf9\u7684\uff0c\u5728\u8fd9\u79cd\u573a\u666f\u4e0b\uff0c<code>:not<\/code>\u4f2a\u7c7b\u662f\u65e0\u89e3\u7684\u3002<\/p>\n<p>\u9664\u975e\u5f3a\u5236\u5c42\u7ea7\u5143\u7d20\uff0c\u4e5f\u5c31\u662f<code>&lt;p&gt;<\/code>\u5143\u7d20\u662f<code>&lt;article&gt;<\/code>\u7684\u76f8\u90bb\u5b50\u5143\u7d20\u5143\u7d20\uff0c\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762CSS\u6ee1\u8db3\u6211\u4eec\u9700\u6c42\uff0c\u4e0d\u8fc7\u9650\u5236\u5f88\u5927\uff0c\u5efa\u8bae\u8fd8\u662f\u4f7f\u7528\u4f20\u7edf\u91cd\u7f6e\u7b56\u7565\uff1a<\/p>\n<pre>:not(article) > p {\r\n    margin: 0;\r\n}<\/pre>\n<h3>\u56db\u3001\u6700\u540e\u5c0f\u7ed3\u4e00\u4e0b\u4e0b<\/h3>\n<p><code>:not<\/code>\u4f2a\u7c7b\u662f\u76ee\u524d\u552f\u4e00\u4e00\u4e2a\u53ef\u4ee5\u5927\u89c4\u6a21\u653e\u5fc3\u4f7f\u7528\u7684\u903b\u8f91\u4f2a\u7c7b\uff0c\u975e\u5e38\u6709\u7528\uff0c\u4f18\u70b9\u4e5f\u5f88\u7a81\u51fa\uff0c\u5927\u5bb6\u53ef\u4ee5\u591a\u7528\u7528\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u5176\u4e2d\u4e5f\u4e0d\u4e4f\u4e00\u4e9b\u4f1a\u8ba9\u4eba\u8e29\u5751\u7684\u5730\u65b9\uff0c\u672c\u6587\u5c31\u4ecb\u7ecd\u8fd9\u51e0\u4e2a\u5927\u5bb6\u53ef\u80fd\u4f1a\u7406\u89e3\u9519\u8bef\u6216\u4f7f\u7528\u9519\u8bef\u7684\u5730\u65b9\uff0c\u81f3\u4e8e\u5176\u4f18\u70b9\u5728\u90a3\u91cc\uff0c\u9650\u4e8e\u4e0d\u662f\u672c\u6587\u91cd\u70b9\uff0c\u4ee5\u540e\u6709\u673a\u4f1a\u5728\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u603b\u4e4b\uff0c\u597d\u7528\uff0c\u5927\u5bb6\u8981\u591a\u7528\u7528\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u5c31\u8bf4\u8fd9\u4e48\u591a\u3002<\/p>\n<p>\u5c0f\u670b\u53cb\u53c8\u751f\u75c5\u4e86\uff0c\u8fde\u7eed\u53bb\u4e863\u5929\u533b\u9662\u4e86\uff0c\u5f85\u4f1a\u513f\u8fd8\u8981\u53bb\u533b\u9662\u6302\u6c34\uff0c\u4e0d\u626f\u4e86\uff0c\u611f\u8c22\u9605\u8bfb\uff0c\u6b22\u8fce\u5206\u4eab\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f62a.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\u5185\u5bb9\u4f60\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u4ee5\u52a0\u5165\u6536\u85cf\u5939\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u800c\u4e14\u8fd8\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\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=8808\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=8808<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201907\/not-cover.jpg\" width=\"161\" height=\"100\" alt=\":not\u4f2a\u7c7b\" class=\"alignright thumb size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u4f2a\u7c7b\u662f\u76ee\u524d\u552f\u4e00\u4e00\u4e2a\u53ef\u4ee5\u5927\u89c4\u6a21\u653e\u5fc3\u4f7f\u7528\u7684\u903b\u8f91\u4f2a\u7c7b\uff0c\u975e\u5e38\u6709\u7528\uff0c\u4f18\u70b9\u4e5f\u5f88\u7a81\u51fa\uff0c\u4f46\u662f\uff0c\u5176\u4e2d\u4e5f\u4e0d\u4e4f\u4e00\u4e9b\u4f1a\u8ba9\u4eba\u8e29\u5751\u7684\u5730\u65b9\uff0c\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u8fd9\u51e0\u4e2a\u53ef\u80fd\u9519\u8bef\u8ba4\u8bc6\u7684\u5730\u65b9\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":[1459,865,1460,1271,1000,1458,843],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/8808"}],"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=8808"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/8808\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=8808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=8808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=8808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}