在ul内嵌套其他html标签,但li除外 [英] nesting other html tags inside ul except li
问题描述
这些代码段在语法上是否正确?我正在使用第一个代码段构建导航(在ul中嵌套标题标签).如果是错误的做法或不好的做法,那么会有什么弊端.
Are these code pieces syntactically correct? I am using first code piece to build a navigation (nesting header tag inside ul). If it is wrong or it is a bad practice what are the drawbacks.
<ul class="site-title left">
<header>
<li><h1>site title</h1></li>
</header>
</ul>
和
<ul class="site-title left">
<span>
<li><h1>site-title</h1></li>
</span>
</ul>
推荐答案
否
根据规范,
ul元素表示项目列表,其中项目的顺序并不重要-也就是说,更改顺序不会实质性地改变文档的含义.
The ul element represents a list of items, where the order of the items is not important — that is, where changing the order would not materially change the meaning of the document. 列表中的项目是ul元素的li元素子节点. 因此,UL元素的子元素必须是 So the children of the UL element must be 更具体地说,它在 More specifically, it says under the 内容模型:
但这是完全合法的: 这篇关于在ul内嵌套其他html标签,但li除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
li
元素.li
elements.ul
标记下表示:ul
tag:
Zero or more li elements.
<ul class="site-title left">
<li><span><h1>site-title</h1></span></li>
</ul>