我们希望使用 CSS 创建一个如下所示的有序列表:
A.
A.1
A.2
B.
C.
C.1
C.2
C.2.1
C.2.2
您如何将父索引包含在子索引中?
你需要使用CSS 计数器 https://developer.mozilla.org/en-US/docs/counters.
例子 (from MDN https://developer.mozilla.org/en-US/docs/counters)
CSS:
ol {
counter-reset: section; /* Creates a new instance of the
section counter with each ol
element */
list-style-type: none;
}
li:before {
counter-increment: section; /* Increments only this instance
of the section counter */
content: counters(section, ".") " "; /* Adds the value of all instances
of the section counter separated
by a ".". */
}
HTML:
<ol>
<li>Entry
<li>Entry
<li>Entry with subentries
<ol>
<li>Entry
<li>Entry
<li>Entry
<li>Entry
</ol>
<li>Entry
<li>Entry
<li>Entry with subentries
<ol>
<li>Entry
<li>Entry
<li>Entry
<li>Entry
</ol>
</ol>
JSFiddle http://jsfiddle.net/8MWdL/1/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)