在H2标题前插入1,2,3..数字



如何修改以下代码,使H2标题前橙色框中的数字可以显示为数字1、2、3。。。?

网站文章示例:https://weblai.co/css-title/

以下是代码:

add_action('wp_head',function(){ ?>
<style>
@import url('https://fonts.googleapis.com/css?family=Noto+Sans+TC');
body {font-family: 'Noto Sans TC', sans-serif;}/*思源黑體*/
article .ast-post-format- .entry-content h2:before {
content: counter(chapter) "";
color: #fff;
background-image: linear-gradient(45deg, #805300 0%, #805300 1%, #F59F00 100%);
box-shadow: 0 1px 4px rgba(0,0,0,0.3);
border-radius: 3px;
padding: 0 0.8rem;
margin: 0 0.8rem 0 0;
}

在此处输入图像描述

看起来你在使用计数器(章节(而没有初始化它。

在正文规则之前添加以下内容:

body {
counter-reset: chapter;                       /* Set a counter named 'section', and its initial value is 0. */
}

来源:

https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters

最新更新