content和counter用法

content和counter插入编号

1.加上连续编号
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>

    h4::before{
      content: counter(num)'.';
      color: #f00;
    }
    h4{
      counter-increment: num;
    }
  </style>
</head>
<body>
    <h4>标题一</h4>
    <h4>标题二</h4>
    <h4>标题三</h4>
    <h4>标题四</h4>
    <h4>标题五</h4>
</body>
</html>
2.指定编号种类
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>

    h4::before{
      content: counter(num,upper-alpha)'.';
      color: #f00;
    }
    h4{
      counter-increment: num;
    }
  </style>
</head>
<body>
    <h4>标题一</h4>
    <h4>标题二</h4>
    <h4>标题三</h4>
    <h4>标题四</h4>
    <h4>标题五</h4>
</body>
</html>
3.编号嵌套
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    h1::before{
      content: counter(num)'.';
    }
    h1{
      counter-increment: num;
      counter-reset: littenum; /* 重置小标题编号 */
    }
    h4::before{
      content: counter(littenum)'.';
    }
    h4{
      counter-increment: littenum;
      margin-left: 40px;
    }
  </style>
</head>
<body>
	<h1>标题</h1>
    <h4>小标题</h4>
    <h4>小标题</h4>
    <h4>小标题</h4>
    <h1>标题</h1>
    <h4>小标题</h4>
    <h4>小标题</h4>
    <h4>小标题</h4>
    <h1>标题</h1>
    <h4>小标题</h4>
    <h4>小标题</h4>
    <h4>小标题</h4>
</body>
</html>
4.总结
  1. counter属性值对多个项目进行连续编号,计数器可任意命名 ( content:counter(计数器名) )
  2. counter-increment属性设置为counter属性值所指定的计数器名
  3. 在编号中追加文字content的设置方法为:( content:'第’counter(计数器名)‘个’ )
  4. 指定编号种类:content:counter(计数器名,种类) 。例如使用大写字母编号时使用 “upper-alpha”。
  5. 编号嵌套时需在大标题中使用counter-reset进行编号重置
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值