{"id":834,"date":"2025-12-20T16:11:17","date_gmt":"2025-12-20T08:11:17","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=834"},"modified":"2025-12-20T16:11:17","modified_gmt":"2025-12-20T08:11:17","slug":"css%e8%ae%a1%e6%95%b0%e5%99%a8-%e8%87%aa%e5%8a%a8%e5%8c%96%e6%96%87%e6%a1%a3%e4%b8%ad%e7%9a%84%e8%87%aa%e5%8a%a8%e7%bc%96%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/20\/css%e8%ae%a1%e6%95%b0%e5%99%a8-%e8%87%aa%e5%8a%a8%e5%8c%96%e6%96%87%e6%a1%a3%e4%b8%ad%e7%9a%84%e8%87%aa%e5%8a%a8%e7%bc%96%e5%8f%b7\/","title":{"rendered":"CSS\u8ba1\u6570\u5668-\u81ea\u52a8\u5316\u6587\u6863\u4e2d\u7684\u81ea\u52a8\u7f16\u53f7"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">CSS \u8ba1\u6570\u5668\uff1a\u81ea\u52a8\u5316\u6587\u6863\u4e2d\u7684\u81ea\u52a8\u7f16\u53f7<\/h3>\n\n\n\n<p>CSS \u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u7684\u673a\u5236\u6765\u5904\u7406\u5143\u7d20\u7684\u81ea\u52a8\u7f16\u53f7\uff0c\u79f0\u4e3a <strong>CSS \u8ba1\u6570\u5668\uff08counter\uff09<\/strong>\u3002\u8fd9\u4f7f\u5f97\u6211\u4eec\u80fd\u591f\u5728\u6587\u6863\u4e2d\u81ea\u52a8\u4e3a\u5143\u7d20\u7f16\u53f7\uff0c\u800c\u4e0d\u9700\u8981\u624b\u52a8\u64cd\u4f5c HTML \u7ed3\u6784\u3002\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u5305\u62ec\uff1a\u4e3a\u5217\u8868\u3001\u7ae0\u8282\u3001\u6761\u76ee\u3001\u56fe\u8868\u7b49\u5143\u7d20\u81ea\u52a8\u751f\u6210\u7f16\u53f7\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001CSS \u8ba1\u6570\u5668\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n\n\n\n<p>CSS \u8ba1\u6570\u5668\u5141\u8bb8\u4f60\u521b\u5efa\u4e00\u4e2a\u53ef\u88ab\u66f4\u65b0\u7684\u8ba1\u6570\u503c\uff0c\u5e76\u5e94\u7528\u5230\u7279\u5b9a\u7684\u5143\u7d20\u4e0a\u3002\u8ba1\u6570\u5668\u503c\u4f1a\u968f\u7740\u6587\u6863\u7684\u6e32\u67d3\u800c\u81ea\u52a8\u589e\u52a0\u6216\u51cf\u5c11\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">CSS \u8ba1\u6570\u5668\u7684\u5e38\u7528\u5c5e\u6027\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>counter-reset<\/code><\/strong>\uff1a\u521d\u59cb\u5316\u8ba1\u6570\u5668\u7684\u8d77\u59cb\u503c\u3002<\/li>\n\n\n\n<li><strong><code>counter-increment<\/code><\/strong>\uff1a\u5728\u6307\u5b9a\u7684\u5143\u7d20\u4e0a\u589e\u52a0\u8ba1\u6570\u5668\u7684\u503c\u3002<\/li>\n\n\n\n<li><strong><code>content<\/code><\/strong>\uff1a\u5728\u5143\u7d20\u7684\u4f2a\u5143\u7d20\u4e2d\u663e\u793a\u8ba1\u6570\u5668\u503c\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u57fa\u672c\u8bed\u6cd5\u548c\u4f7f\u7528\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u521d\u59cb\u5316\u8ba1\u6570\u5668<\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u9700\u8981\u4f7f\u7528 <code>counter-reset<\/code> \u5c5e\u6027\u6765\u521d\u59cb\u5316\u8ba1\u6570\u5668\u3002\u8fd9\u4e2a\u5c5e\u6027\u901a\u5e38\u5728\u5305\u542b\u591a\u4e2a\u9700\u8981\u81ea\u52a8\u7f16\u53f7\u7684\u5143\u7d20\u7684\u7236\u5bb9\u5668\u4e0a\u8bbe\u7f6e\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.container {\n  counter-reset: section; \/* \u521d\u59cb\u5316\u8ba1\u6570\u5668 &quot;section&quot; *\/\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">2. \u589e\u52a0\u8ba1\u6570\u5668<\/h3>\n\n\n\n<p>\u4f7f\u7528 <code>counter-increment<\/code> \u5c5e\u6027\u6765\u5728\u6bcf\u4e2a\u9700\u8981\u81ea\u52a8\u7f16\u53f7\u7684\u5143\u7d20\u4e0a\u589e\u52a0\u8ba1\u6570\u5668\u503c\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nh2 {\n  counter-increment: section; \/* \u5728\u6bcf\u4e2a h2 \u5143\u7d20\u4e0a\u9012\u589e\u8ba1\u6570\u5668 *\/\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">3. \u663e\u793a\u8ba1\u6570\u5668\u503c<\/h3>\n\n\n\n<p>\u4f7f\u7528\u4f2a\u5143\u7d20 <code>::before<\/code> \u6216 <code>::after<\/code>\uff0c\u914d\u5408 <code>content<\/code> \u5c5e\u6027\uff0c\u6765\u663e\u793a\u8ba1\u6570\u5668\u7684\u5f53\u524d\u503c\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nh2::before {\n  content: &quot;Section &quot; counter(section) &quot;. &quot;; \/* \u663e\u793a\u8ba1\u6570\u5668\u503c *\/\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5b8c\u6574\u793a\u4f8b\uff1a\u81ea\u52a8\u7f16\u53f7\u7684\u7ae0\u8282<\/h2>\n\n\n\n<p>\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u6765\u6f14\u793a\u5982\u4f55\u5728 HTML \u6587\u6863\u4e2d\u4f7f\u7528 CSS \u81ea\u52a8\u4e3a\u7ae0\u8282\u6807\u9898\u6dfb\u52a0\u7f16\u53f7\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">HTML \u7ed3\u6784\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;div class=&quot;container&quot;&gt;\n  &amp;lt;h2&gt;Introduction&amp;lt;\/h2&gt;\n  &amp;lt;p&gt;This is the introduction paragraph.&amp;lt;\/p&gt;\n\n  &amp;lt;h2&gt;Chapter 1: The Beginning&amp;lt;\/h2&gt;\n  &amp;lt;p&gt;This is the first chapter content.&amp;lt;\/p&gt;\n\n  &amp;lt;h2&gt;Chapter 2: The Journey&amp;lt;\/h2&gt;\n  &amp;lt;p&gt;This is the second chapter content.&amp;lt;\/p&gt;\n&amp;lt;\/div&gt;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">CSS \u6837\u5f0f\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.container {\n  counter-reset: section; \/* \u521d\u59cb\u5316\u8ba1\u6570\u5668 *\/\n}\n\nh2 {\n  counter-increment: section; \/* \u589e\u52a0\u8ba1\u6570\u5668 *\/\n}\n\nh2::before {\n  content: &quot;Chapter &quot; counter(section) &quot;: &quot;; \/* \u5728\u7ae0\u8282\u524d\u52a0\u4e0a\u7f16\u53f7 *\/\n  font-weight: bold;\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5728 <code>.container<\/code> \u5143\u7d20\u4e0a\u4f7f\u7528 <code>counter-reset<\/code> \u521d\u59cb\u5316\u8ba1\u6570\u5668 <code>section<\/code>\uff0c\u4ece 0 \u5f00\u59cb\u3002<\/li>\n\n\n\n<li>\u5728\u6bcf\u4e2a <code>h2<\/code> \u5143\u7d20\u4e0a\u4f7f\u7528 <code>counter-increment<\/code> \u589e\u52a0\u8ba1\u6570\u5668\u503c\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>::before<\/code> \u4f2a\u5143\u7d20\u548c <code>counter(section)<\/code> \u663e\u793a\u8ba1\u6570\u5668\u7684\u5f53\u524d\u503c\uff0c\u5f62\u6210\u81ea\u52a8\u7f16\u53f7\u6548\u679c\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u51fa\u6548\u679c\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nChapter 1: Introduction\nThis is the introduction paragraph.\n\nChapter 2: Chapter 1: The Beginning\nThis is the first chapter content.\n\nChapter 3: Chapter 2: The Journey\nThis is the second chapter content.\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u6dfb\u52a0\u66f4\u590d\u6742\u7684\u7f16\u53f7\u683c\u5f0f<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u5b50\u7ae0\u8282\u7f16\u53f7<\/strong><\/h3>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u4e3a\u5b50\u7ae0\u8282\u8bbe\u7f6e\u4e00\u4e2a\u5d4c\u5957\u8ba1\u6570\u5668\uff0c\u521b\u5efa\u7ae0\u8282\u7684\u5c42\u6b21\u5316\u7f16\u53f7\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">HTML \u7ed3\u6784\uff1a<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;div class=&quot;container&quot;&gt;\n  &amp;lt;h2&gt;Main Chapter&amp;lt;\/h2&gt;\n  &amp;lt;h3&gt;Subsection 1.1&amp;lt;\/h3&gt;\n  &amp;lt;h3&gt;Subsection 1.2&amp;lt;\/h3&gt;\n  \n  &amp;lt;h2&gt;Main Chapter 2&amp;lt;\/h2&gt;\n  &amp;lt;h3&gt;Subsection 2.1&amp;lt;\/h3&gt;\n&amp;lt;\/div&gt;\n\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">CSS \u6837\u5f0f\uff1a<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.container {\n  counter-reset: main; \/* \u521d\u59cb\u5316\u4e3b\u7ae0\u8282\u8ba1\u6570\u5668 *\/\n}\n\nh2 {\n  counter-increment: main; \/* \u589e\u52a0\u4e3b\u7ae0\u8282\u8ba1\u6570\u5668 *\/\n}\n\nh2::before {\n  content: &quot;Chapter &quot; counter(main) &quot;. &quot;; \/* \u663e\u793a\u4e3b\u7ae0\u8282\u7f16\u53f7 *\/\n}\n\nh3 {\n  counter-reset: subsection; \/* \u521d\u59cb\u5316\u5b50\u7ae0\u8282\u8ba1\u6570\u5668 *\/\n  counter-increment: subsection; \/* \u589e\u52a0\u5b50\u7ae0\u8282\u8ba1\u6570\u5668 *\/\n}\n\nh3::before {\n  content: counter(main) &quot;.&quot; counter(subsection) &quot; &quot;; \/* \u663e\u793a\u5b50\u7ae0\u8282\u7f16\u53f7 *\/\n  font-style: italic;\n}\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>.container<\/code> \u4e2d\u7684 <code>counter-reset: main<\/code> \u7528\u6765\u521d\u59cb\u5316\u4e3b\u7ae0\u8282\u7684\u8ba1\u6570\u5668\u3002<\/li>\n\n\n\n<li><code>h2<\/code> \u589e\u52a0\u4e3b\u7ae0\u8282\u7684\u8ba1\u6570\u5668\uff0c<code>h2::before<\/code> \u663e\u793a\u4e3b\u7ae0\u8282\u7f16\u53f7\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e <code>h3<\/code>\uff0c\u6211\u4eec\u4f7f\u7528 <code>counter-reset<\/code> \u6765\u521d\u59cb\u5316\u5b50\u7ae0\u8282\u8ba1\u6570\u5668\uff0c\u5e76\u7528 <code>counter(main)<\/code> \u548c <code>counter(subsection)<\/code> \u6765\u663e\u793a\u5c42\u6b21\u5316\u7684\u7f16\u53f7\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u51fa\u6548\u679c\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nChapter 1. Main Chapter\n1.1 Subsection 1.1\n1.2 Subsection 1.2\n\nChapter 2. Main Chapter 2\n2.1 Subsection 2.1\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u6587\u7ae0\u6216\u4e66\u7c4d\u76ee\u5f55<\/strong>\uff1a\u4e3a\u6bcf\u4e00\u7ae0\u8282\u3001\u5b50\u7ae0\u8282\u81ea\u52a8\u7f16\u53f7\uff0c\u4fbf\u4e8e\u5feb\u901f\u5bfc\u822a\u3002<\/li>\n\n\n\n<li><strong>\u6709\u5e8f\u5217\u8868<\/strong>\uff1a\u901a\u8fc7 <code>counter<\/code> \u53ef\u4ee5\u4e3a <code>&lt;ol><\/code>\uff08\u6709\u5e8f\u5217\u8868\uff09\u4e2d\u7684\u9879\u76ee\u81ea\u52a8\u7f16\u53f7\u3002<\/li>\n\n\n\n<li><strong>FAQ \u6216\u6587\u6863<\/strong>\uff1a\u81ea\u52a8\u7f16\u53f7\u95ee\u7b54\u6216\u6761\u76ee\uff0c\u63d0\u5347\u6587\u6863\u7684\u7ec4\u7ec7\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/li>\n\n\n\n<li><strong>\u56fe\u8868\u6216\u56fe\u7247\u7f16\u53f7<\/strong>\uff1a\u4e3a\u56fe\u8868\u3001\u56fe\u7247\u7b49\u5143\u7d20\u81ea\u52a8\u6dfb\u52a0\u7f16\u53f7\uff0c\u65b9\u4fbf\u5f15\u7528\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u603b\u7ed3<\/h2>\n\n\n\n<p>\u901a\u8fc7 CSS \u7684\u8ba1\u6570\u5668\u529f\u80fd\uff0c\u6211\u4eec\u80fd\u591f\u5728\u4e0d\u4fee\u6539 HTML \u7684\u60c5\u51b5\u4e0b\uff0c\u4e3a\u6587\u6863\u4e2d\u7684\u5143\u7d20\u81ea\u52a8\u751f\u6210\u7f16\u53f7\u3002\u8fd9\u4e0d\u4ec5\u53ef\u4ee5\u7b80\u5316\u5f00\u53d1\u8fc7\u7a0b\uff0c\u8fd8\u80fd\u591f\u4e3a\u590d\u6742\u7684\u9875\u9762\u5e03\u5c40\u63d0\u4f9b\u7075\u6d3b\u7684\u7f16\u53f7\u683c\u5f0f\u3002CSS \u8ba1\u6570\u5668\u7684 <strong><code>counter-reset<\/code><\/strong>\u3001<strong><code>counter-increment<\/code><\/strong> \u548c <strong><code>content<\/code><\/strong> \u5c5e\u6027\u4f7f\u5f97\u81ea\u52a8\u7f16\u53f7\u7684\u5b9e\u73b0\u53d8\u5f97\u975e\u5e38\u65b9\u4fbf\u548c\u5f3a\u5927\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS \u8ba1\u6570\u5668\uff1a\u81ea\u52a8\u5316\u6587\u6863\u4e2d\u7684\u81ea\u52a8\u7f16\u53f7 CSS \u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u7684\u673a\u5236\u6765\u5904\u7406\u5143\u7d20\u7684&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/20\/css%e8%ae%a1%e6%95%b0%e5%99%a8-%e8%87%aa%e5%8a%a8%e5%8c%96%e6%96%87%e6%a1%a3%e4%b8%ad%e7%9a%84%e8%87%aa%e5%8a%a8%e7%bc%96%e5%8f%b7\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-834","post","type-post","status-publish","format-standard","hentry","category-css"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=834"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/834\/revisions"}],"predecessor-version":[{"id":835,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/834\/revisions\/835"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}