{"id":3454,"date":"2024-11-10T09:09:39","date_gmt":"2024-11-10T01:09:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3454\/"},"modified":"2024-11-10T09:09:39","modified_gmt":"2024-11-10T01:09:39","slug":"%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8-css-%e9%80%89%e4%b8%ad%e6%bf%80%e6%b4%bb%e6%a0%87%e7%ad%be%e5%b9%b6%e5%bd%b1%e5%93%8d%e7%9b%b8%e9%82%bb%e5%85%83%e7%b4%a0%e7%9a%84%e6%a0%b7%e5%bc%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3454\/","title":{"rendered":"\u5982\u4f55\u5229\u7528 CSS \u9009\u4e2d\u6fc0\u6d3b\u6807\u7b7e\u5e76\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\u7684\u6837\u5f0f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173104074353749.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5229\u7528 CSS \u9009\u4e2d\u6fc0\u6d3b\u6807\u7b7e\u5e76\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\u7684\u6837\u5f0f\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5229\u7528 CSS \u9009\u4e2d\u6fc0\u6d3b\u6807\u7b7e\u5e76\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\u7684\u6837\u5f0f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5229\u7528  \u9009\u4e2d\u6fc0\u6d3b\u6807\u7b7e\u5e76\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\uff1f<\/strong><\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u6fc0\u6d3b\u6807\u7b7e\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\u7684\u6837\u5f0f\u9700\u6c42\uff0c\u53ef\u4ee5\u901a\u8fc7 <strong>:has<\/strong> \u9009\u62e9\u5668\u6765\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5177\u4f53\u64cd\u4f5c\uff1a<\/p>\n<p>\u5bf9\u4e8e\u6fc0\u6d3b\u6807\u7b7e\u76f8\u90bb\u540e\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u5728 css \u4e2d\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u8bbe\u7f6e\uff1a<\/p>\n<pre>li:has(+li.active) {\n  border-radius: 0 0 10px 0;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u540c\u6837\u5730\uff0c\u5bf9\u4e8e\u6fc0\u6d3b\u6807\u7b7e\u76f8\u90bb\u524d\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u8bbe\u7f6e\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>li:has(~:nth-last-child(1).active) {\n  border-radius: 0 10px 0 0;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<strong>:has<\/strong> \u9009\u62e9\u5668\u5728\u67d0\u4e9b\u8001\u65e7\u6d4f\u89c8\u5668\u4e2d\u517c\u5bb9\u6027\u8f83\u5dee\u3002\u56e0\u6b64\uff0c\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b javascript \u4ee3\u7801\u8fdb\u884c\u517c\u5bb9\u6027\u5904\u7406\uff1a<\/p>\n<pre>document.querySelectorAll('li').forEach((item) =&gt; {\n  item.addEventListener('click', (e) =&gt; {\n    if (!e.target.classList.contains('active')) {\n      e.target.classList.add('active');\n    }\n\n    const prevSibling = e.target.previousElementSibling;\n    const nextSibling = e.target.nextElementSibling;\n\n    if (nextSibling &amp;&amp; !nextSibling.classList.contains('active')) {\n      nextSibling.style.borderRadius = '0 0 10px 0';\n    }\n\n    if (nextSibling &amp;&amp; nextSibling.classList.contains('active')) {\n      nextSibling.style.borderRadius = '0 10px 10px 0';\n    }\n\n    if (prevSibling &amp;&amp; !prevSibling.classList.contains('active')) {\n      prevSibling.style.borderRadius = '0 10px 0 0';\n    }\n\n    if (prevSibling &amp;&amp; prevSibling.classList.contains('active')) {\n      prevSibling.style.borderRadius = '10px 10px 0 0';\n    }\n  });\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5229\u7528 CSS \u9009\u4e2d\u6fc0\u6d3b\u6807\u7b7e\u5e76\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\u7684\u6837\u5f0f\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5229\u7528 \u9009\u4e2d\u6fc0\u6d3b\u6807\u7b7e\u5e76\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\uff1f \u4e3a\u4e86\u5b9e\u73b0\u6fc0\u6d3b\u6807\u7b7e\u5f71\u54cd\u76f8\u90bb\u5143\u7d20\u7684\u6837\u5f0f\u9700\u6c42\uff0c\u53ef\u4ee5\u901a\u8fc7 :has \u9009\u62e9\u5668\u6765\u5b9e\u73b0\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5177\u4f53\u64cd\u4f5c\uff1a \u5bf9\u4e8e\u6fc0\u6d3b\u6807\u7b7e\u76f8\u90bb\u540e\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u5728 css \u4e2d\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u8bbe\u7f6e\uff1a li:has(+li.active) { border-radius: 0 0 10px 0; } \u767b\u5f55\u540e\u590d\u5236 \u540c\u6837\u5730\uff0c\u5bf9\u4e8e\u6fc0\u6d3b\u6807\u7b7e\u76f8\u90bb\u524d\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u8bbe\u7f6e\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b li:has(~:nth-last-child(1).active) { border-radius: 0 10px 0 0; } \u767b\u5f55\u540e\u590d\u5236 \u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c:has \u9009\u62e9\u5668\u5728\u67d0\u4e9b\u8001\u65e7\u6d4f\u89c8\u5668\u4e2d\u517c\u5bb9\u6027\u8f83\u5dee\u3002\u56e0\u6b64\uff0c\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b javascript \u4ee3\u7801\u8fdb\u884c\u517c\u5bb9\u6027\u5904\u7406\uff1a document.querySelectorAll(&#8216;li&#8217;).forEach((item) =&gt; { item.addEventListener(&#8216;click&#8217;, (e) =&gt; { if (!e.target.classList.contains(&#8216;active&#8217;)) { e.target.classList.add(&#8216;active&#8217;); } const prevSibling = e.target.previousElementSibling; const nextSibling = e.target.nextElementSibling; if (nextSibling &amp;&amp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3454","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3454","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3454"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3454\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}