{"id":4094,"date":"2024-11-10T10:44:12","date_gmt":"2024-11-10T02:44:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4094\/"},"modified":"2024-11-10T10:44:12","modified_gmt":"2024-11-10T02:44:12","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-css-%e9%80%89%e6%8b%a9%e5%99%a8%e5%9c%a8-html-%e7%bb%93%e6%9e%84%e4%b8%ad%e9%80%89%e5%8f%96%e6%95%b0%e9%87%8f%e4%b8%8d%e5%9b%ba%e5%ae%9a%e7%9a%84%e5%ad%90%e5%85%83%e7%b4%a0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4094\/","title":{"rendered":"\u5982\u4f55\u7528 CSS \u9009\u62e9\u5668\u5728 HTML \u7ed3\u6784\u4e2d\u9009\u53d6\u6570\u91cf\u4e0d\u56fa\u5b9a\u7684\u5b50\u5143\u7d20\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173122441322906.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u7528 CSS \u9009\u62e9\u5668\u5728 HTML \u7ed3\u6784\u4e2d\u9009\u53d6\u6570\u91cf\u4e0d\u56fa\u5b9a\u7684\u5b50\u5143\u7d20\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528 CSS \u9009\u62e9\u5668\u5728 HTML \u7ed3\u6784\u4e2d\u9009\u53d6\u6570\u91cf\u4e0d\u56fa\u5b9a\u7684\u5b50\u5143\u7d20\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7  \u9009\u62e9\u975e\u56fa\u5b9a\u6570\u91cf\u5b50\u5143\u7d20<\/strong><\/p>\n<p>\u5728 html \u7ed3\u6784\u4e2d\uff0c\u5143\u7d20\u7684\u4e2a\u6570\u901a\u5e38\u662f\u4e0d\u56fa\u5b9a\u7684\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b html \u4ee3\u7801\u5305\u542b\u6570\u91cf\u4e0d\u5b9a\u7684 activebar \u548c item \u5b50\u5143\u7d20\uff1a<\/p>\n<pre>&lt;div class=\"main\"&gt;\n  &lt;div class=\"activebar\"&gt;&lt;\/div&gt;\n  &lt;div class=\"activebar\"&gt;&lt;\/div&gt;*n\n  &lt;div class=\"activebar\"&gt;&lt;\/div&gt;\n  &lt;div class=\"item\"&gt;&lt;\/div&gt;\n  &lt;div class=\"item\"&gt;&lt;\/div&gt;*n\n  &lt;div class=\"item\"&gt;&lt;\/div&gt;\n&lt;\/div&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u9009\u62e9\u7b2c\u4e00\u4e2a item \u5b50\u5143\u7d20<\/strong><\/p>\n<p>\u4e3a\u4e86\u5728\u5143\u7d20\u4e2a\u6570\u4e0d\u56fa\u5b9a\u7684\u60c5\u51b5\u4e0b\u9009\u62e9\u7b2c\u4e00\u4e2a item \u5b50\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528 css \u9009\u62e9\u5668 :nth-child()\u3002\u8be5\u9009\u62e9\u5668\u5141\u8bb8\u6307\u5b9a\u7236\u5143\u7d20\u4e2d\u7b2c\u51e0\u4e2a\u5b50\u5143\u7d20\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>:nth-child(n)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cn \u53ef\u4ee5\u662f\u4ee5\u4e0b\u51e0\u79cd\u503c\uff1a<\/p>\n<ul>\n<li> <strong>\u6570\u5b57\uff1a<\/strong>\u6307\u5b9a\u8981\u9009\u62e9\u7684\u7b2c\u51e0\u4e2a\u5b50\u5143\u7d20\uff0c\u4f8b\u5982 :nth-child(1) \u9009\u62e9\u7b2c\u4e00\u4e2a\u5b50\u5143\u7d20\u3002<\/li>\n<li> <strong>\u5173\u952e\u5b57 odd\uff1a<\/strong>\u9009\u62e9\u6240\u6709\u5947\u6570\u4e2a\u7684\u5b50\u5143\u7d20\uff0c\u4f8b\u5982 :nth-child(odd) \u9009\u62e9\u7b2c\u4e00\u4e2a\u3001\u7b2c\u4e09\u4e2a\u3001\u7b2c\u4e94\u4e2a\u5b50\u5143\u7d20\u7b49\u3002<\/li>\n<li> <strong>\u5173\u952e\u5b57 even\uff1a<\/strong>\u9009\u62e9\u6240\u6709\u5076\u6570\u4e2a\u7684\u5b50\u5143\u7d20\uff0c\u4f8b\u5982 :nth-child(even) \u9009\u62e9\u7b2c\u4e8c\u4e2a\u3001\u7b2c\u56db\u4e2a\u3001\u7b2c\u516d\u4e2a\u5b50\u5143\u7d20\u7b49\u3002<\/li>\n<\/ul>\n<p>\u8981\u9009\u62e9\u7b2c\u4e00\u4e2a item \u5b50\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u9009\u62e9\u5668\uff1a<\/p>\n<pre>.main .item:nth-child(1)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u9009\u62e9\u5668\u5c06\u5339\u914d mn \u7c7b\u4e0b\u7684\u7b2c\u4e00\u4e2a item \u7c7b\u5143\u7d20\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 :nth-child() \u9009\u62e9\u5668\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u5b50\u5143\u7d20\u5fc5\u987b\u662f\u76f4\u63a5\u5b50\u5143\u7d20\uff0c\u5373\u4e0d\u53ef\u5d4c\u5957\u3002<\/li>\n<li>\u4ece 1 \u5f00\u59cb\u8ba1\u6570\uff0c\u800c\u4e0d\u662f 0\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7528 CSS \u9009\u62e9\u5668\u5728 HTML \u7ed3\u6784\u4e2d\u9009\u53d6\u6570\u91cf\u4e0d\u56fa\u5b9a\u7684\u5b50\u5143\u7d20\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>\u901a\u8fc7 \u9009\u62e9\u975e\u56fa\u5b9a\u6570\u91cf\u5b50\u5143\u7d20 \u5728 html \u7ed3\u6784\u4e2d\uff0c\u5143\u7d20\u7684\u4e2a\u6570\u901a\u5e38\u662f\u4e0d\u56fa\u5b9a\u7684\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b html \u4ee3\u7801\u5305\u542b\u6570\u91cf\u4e0d\u5b9a\u7684 activebar \u548c item \u5b50\u5143\u7d20\uff1a &lt;div class=&#8221;main&#8221;&gt; &lt;div class=&#8221;activebar&#8221;&gt;&lt;\/div&gt; &lt;div class=&#8221;activebar&#8221;&gt;&lt;\/div&gt;*n &lt;div class=&#8221;activebar&#8221;&gt;&lt;\/div&gt; &lt;div class=&#8221;item&#8221;&gt;&lt;\/div&gt; &lt;div class=&#8221;item&#8221;&gt;&lt;\/div&gt;*n &lt;div class=&#8221;item&#8221;&gt;&lt;\/div&gt; &lt;\/div&gt; \u767b\u5f55\u540e\u590d\u5236 \u9009\u62e9\u7b2c\u4e00\u4e2a item \u5b50\u5143\u7d20 \u4e3a\u4e86\u5728\u5143\u7d20\u4e2a\u6570\u4e0d\u56fa\u5b9a\u7684\u60c5\u51b5\u4e0b\u9009\u62e9\u7b2c\u4e00\u4e2a item \u5b50\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528 css \u9009\u62e9\u5668 :nth-child()\u3002\u8be5\u9009\u62e9\u5668\u5141\u8bb8\u6307\u5b9a\u7236\u5143\u7d20\u4e2d\u7b2c\u51e0\u4e2a\u5b50\u5143\u7d20\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b :nth-child(n) \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0cn \u53ef\u4ee5\u662f\u4ee5\u4e0b\u51e0\u79cd\u503c\uff1a \u6570\u5b57\uff1a\u6307\u5b9a\u8981\u9009\u62e9\u7684\u7b2c\u51e0\u4e2a\u5b50\u5143\u7d20\uff0c\u4f8b\u5982 :nth-child(1) \u9009\u62e9\u7b2c\u4e00\u4e2a\u5b50\u5143\u7d20\u3002 \u5173\u952e\u5b57 odd\uff1a\u9009\u62e9\u6240\u6709\u5947\u6570\u4e2a\u7684\u5b50\u5143\u7d20\uff0c\u4f8b\u5982 :nth-child(odd) \u9009\u62e9\u7b2c\u4e00\u4e2a\u3001\u7b2c\u4e09\u4e2a\u3001\u7b2c\u4e94\u4e2a\u5b50\u5143\u7d20\u7b49\u3002 \u5173\u952e\u5b57 even\uff1a\u9009\u62e9\u6240\u6709\u5076\u6570\u4e2a\u7684\u5b50\u5143\u7d20\uff0c\u4f8b\u5982 :nth-child(even) \u9009\u62e9\u7b2c\u4e8c\u4e2a\u3001\u7b2c\u56db\u4e2a\u3001\u7b2c\u516d\u4e2a\u5b50\u5143\u7d20\u7b49\u3002 \u8981\u9009\u62e9\u7b2c\u4e00\u4e2a item \u5b50\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u9009\u62e9\u5668\uff1a [&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-4094","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4094","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=4094"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4094\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}