html - 订单列表的CSS设计

标签 html css

我有这样的 HTML 和 CSS,我想对其进行设计。

CSS:

ol li {list-style-type: decimal-leading-zero;}

HTML:

<ol>
<li>One</li>
<li>Two</li>
<li>Three
<ol>
<li>Three.One</li>
<li>Three.Two</li>
</ol>
</li>
<li>Four</li>
</ol>

上面是我的 HTML 和 CSS 内容。如您所见,我不想在此订单列表中使用任何 span 元素或 anchor 标记。那么,我可以为li的OL(order list)编号和文本内容制作不同的颜色吗?我想为数字制作红色,为 li 内容制作黑色。

最佳答案

这是 solution .

ol li {
  list-style-type: decimal-leading-zero;
}

ol {
  counter-reset: li;
}

ol li {
  list-style-type: none;
  counter-increment: li;
  position: relative;
}

ol li:before {
  content: counter(li, decimal-leading-zero) ".";
  position: absolute;
  left: -2.6em;
  width: 2em;
  text-align: right;
  color: #f00;
}
<ol>
  <li>One</li>
  <li>Two</li>
  <li>Three
    <ol>
      <li>Three.One</li>
      <li>Three.Two</li>
    </ol>
  </li>
  <li>Four</li>
</ol>

希望这对您有所帮助。

关于html - 订单列表的CSS设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16456176/

相关文章:

mozilla firefox 和 internet explorer 中的 CSS 不同输出

html - 如何在页眉和页脚之间显示一个空的 div?

html - Ionic Build 在不存在的地方创建 DIV?

PHP 和 SQL : managing log-in via databases

html - 单击 IE 表格中的按钮

html - 如何防止 Chrome 中的 HTML 复选框或单选按钮缩小?

html - 多个 ID 选择器不起作用

jquery - 选择某些元素组

css - 溢出 : hidden not applying to a pseudo element in Chrome

jquery 和 css3 slider 在一个方向上工作,但在另一个方向上不起作用