CSS计数器CSS counters给数字后面加背景

2020-06-162491次阅读css模块css

CSS counters是CSS2.1中自动计数编号部分的实现。计数器的值通过使用counter-reset 和 counter-increment 操作,在 content 上应用 counter() 或 counters()函数来显示在页面上。

body {
  counter-reset: section;           /* 重置计数器成0 */
}
h3:before {
  counter-increment: section;      /* 增加计数器值 */
  content: "Section " counter(section) ": "; /* 显示计数器 */
}

CSS计数器CSS counters给数字后面加背景

ol {
  list-style: none;
  counter-reset: steps;
}
ol li {
  counter-increment: steps;
}
ol li::before {
  content: counter(steps);
  margin-right: 0.5rem;
  background: #ff6f00;
  color: white;
  width: 1.2em;
  height: 1.2em;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  line-height: 1.2em;
}
ol ol li::before {
  background: darkorchid;
}

上一篇: FormData与Content-Type类型关系  下一篇: Type 'Timeout' is not assignable to type 'number'  

CSS计数器CSS counters给数字后面加背景相关文章