2017-05-25 29 views
2

我正在尝试在文件中使用HTML编写目录。出现在我的目录中的编号是有缺陷的。如何修改以下CSSHTML,以便我的Output中的第四个项目符号为4而不是3.4错误编号在HTML目录中的内容

ol { 
 
    counter-reset: item; 
 
} 
 

 
ol li { 
 
    line-height: 30px; 
 
} 
 

 
ol ol li { 
 
    line-height: 20px; 
 
} 
 

 
li { 
 
    display: block; 
 
} 
 

 
li:before { 
 
    content: counters(item, ".")" "; 
 
    counter-increment: item; 
 
}
<ol> 
 
    <li> 
 
    <a href="#lorem_ipsum">lorem ipsum</a> 
 
    </li> 
 
    <li> 
 
    <a href="#set">Set</a> 
 
    </li> 
 
    <li> 
 
    <a href="#title">Title</a> 
 
    </li> 
 
    <ol> 
 
    <li> 
 
     <a href="#Class">Class</a> 
 
    </li> 
 
    <li> 
 
     <a href="#Something">Something</a> 
 
    </li> 
 
    <li> 
 
     <a href="#action">Action</a> 
 
    </li> 
 
    </ol> 
 
    <li> 
 
    <a href="#table_of_references">Table of References</a> 
 
    </li> 
 
</ol>

输出

1. Lorem Ipsum 
2. Set 
3. Title 
    3.1. Class 
    3.2. Something 
    3.3. Action 
3.4. Table of References 
+3

_“错误编号中的HTML内容表” _ - 好了,写_invalid_ HTML,得到意想不到的结“ol”不能是“ol”的孩子。 – CBroe

回答

5

正如评论所说(@乔恩P):你的HTML是无效的。您不能让ol作为ol的直系后裔,它需要包装在li中。

要嵌套列表正确,只是移动子ol第三李里,检查下面的例子:

REF:https://developer.mozilla.org/en/docs/Web/HTML/Element/ol

enter image description here

ol { 
 
    counter-reset: item; 
 
} 
 

 
ol li { 
 
    line-height: 30px; 
 
} 
 

 
ol ol li { 
 
    line-height: 20px; 
 
} 
 

 
li { 
 
    display: block; 
 
} 
 

 
li:before { 
 
    content: counters(item, ".")" "; 
 
    counter-increment: item; 
 
}
<ol> 
 
    <li> 
 
    <a href="#lorem_ipsum">lorem ipsum</a> 
 
    </li> 
 
    <li> 
 
    <a href="#set">Set</a> 
 
    </li> 
 
    <li> 
 
    <a href="#title">Title</a> 
 
    <ol> 
 
     <li> 
 
     <a href="#Class">Class</a> 
 
     </li> 
 
     <li> 
 
     <a href="#Something">Something</a> 
 
     </li> 
 
     <li> 
 
     <a href="#action">Action</a> 
 
     </li> 
 
    </ol> 
 
    </li> 
 
    <li> 
 
    <a href="#table_of_references">Table of References</a> 
 
    </li> 
 
</ol>

+0

欢迎来到stackoverflow @ user7623610,如果有任何答案可以帮助你[把它投票](http://meta.stackexchange.com/questions/173399/how-to-upvote-on-stack-overflow),如果答案是什么你希望为未来的读者标记为[正确答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。谢谢! –

1

你标题后关闭您的L1标签太早 - 移动它的OL部分的下方,这样的:

<ol> 
    <li> 
    <a href="#lorem_ipsum">lorem ipsum</a> 
    </li> 
    <li> 
    <a href="#set">Set</a> 
    </li> 
    <li> 
    <a href="#title">Title</a> 
    <ol> 
    <li> 
     <a href="#Class">Class</a> 
    </li> 
    <li> 
     <a href="#Something">Something</a> 
    </li> 
    <li> 
     <a href="#action">Action</a> 
    </li> 
    </ol> 
    </li> 
    <li> 
    <a href="#table_of_references">Table of References</a> 
    </li> 
</ol>