html - 在 CSS 中报告部分样式列表编号?

标签 html css

现在我知道了“正常”的 CSS 列表样式(罗马、拉丁等),当然在过去的几年里,它们在不允许像这样的事情方面有些不灵活:

(一)

一)

只有

一个。

现在我相信您可以使用 :before 和 :after 伪元素获得上述效果。那是对的吗?如果可以的话,浏览器兼容性如何?

然而,我的主要问题是我想要报告样式编号:

  1. 简介 1.1 目标 1.2 假设 1.3 限制 1.3.1 ...
  2. 新科 ...

等等。

CSS 可以做到这一点吗?如果可以,浏览器的兼容性如何?

最佳答案

参见 Generated content, automatic numbering, and lists .

This example shows a way to number chapters and sections with "Chapter 1", "1.1", "1.2", etc.

H1:before {
    content: "Chapter " counter(chapter) ". ";
    counter-increment: chapter;  /* Add 1 to chapter */
    counter-reset: section;      /* Set section to 0 */
}
H2:before {
    content: counter(chapter) "." counter(section) " ";
    counter-increment: section;
}

编辑:quirksmode.org在浏览器上有更好的 css 支持表。几乎所有浏览器,IE8b2 之前的 IE 除外。所以是的,完全没用。

关于html - 在 CSS 中报告部分样式列表编号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/349060/

相关文章:

html - float div 未正确换行

html - 左右溢出的居中div

c# - 无法使用 html 文本框登录

css - 有时 Cassette 不会重写背景图像规则

java - 在编辑和非编辑模式之间切换时防止 GET EditText Cell 翻转

android - Android 4+ 浏览器上固定 header 上方的间隙

html - CSS 2.1 : Wrap Text Inside Div

html - Bootstrap data-affix/position-fixed col 与其他 col 重叠

html - 为什么我的背景图片不显示?

html - 中间对齐元素