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

时间:2011-10-17 08:20:19

标签: html

我想要这个:

1. Main
  1.1 sub1
  1.2 sub2
2. Main2
  2.1 sub3

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

3 个答案:

答案 0 :(得分: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 */

答案 1 :(得分:8)

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

li li:before {
  counter-increment: item;
  content: counter(item) ". ";
}

li li只是在第一级之后才这样做。)

您可能也需要counter-reset

答案 2 :(得分:0)

body
{
    counter-reset:section;
}

h1
{
    counter-reset:subsection;
}

h1:before
{
    counter-increment:section;
    content:"Section " counter(section) ". ";
}

h2:before 
{
    counter-increment:subsection;
    content:counter(section) "." counter(subsection) " ";
}
body
{
    counter-reset:section;
}

这是反增量和反重置的样本。