是否可以在HTML中创建多级有序列表?

Roc*_*cky 7 html

我要这个:

1. Main
  1.1 sub1
  1.2 sub2
2. Main2
  2.1 sub3
Run Code Online (Sandbox Code Playgroud)

是否可以在HTML中执行此操作?谢谢.

小智 14

这个解决方案对我有用:

/* hide original list counter */
ol li {display:block;} 
/* OR */
ol {list-style:none;}  

ol > li:first-child {counter-reset: item;} /* reset counter */
ol > li {counter-increment: item;} /* increment counter */
ol > li:before {content:counters(item, ".") ". "; font-weight:bold;} /* print counter */
Run Code Online (Sandbox Code Playgroud)


Ari*_*iel 8

是的,至少在现代浏览器中:

li li:before {
  counter-increment: item;
  content: counter(item) ". ";
}
Run Code Online (Sandbox Code Playgroud)

(这li li是在第一级之后才这样做.)

你可能也需要counter-reset.