允许ul的子元素 [英] Allowed child elements of ul
问题描述
< ul>
< li> ...< / li>
< li> ...< / li>
< li> ...< / li>
< li> ...< / li>
< li> ...< / li>
< div>
< li> ...< / li>
< li> ...< / li>
< / div>
< / ul>
我从来没有见过 div
标签为之前的 ul
元素的子元素。 HTML在浏览器中呈现良好。
这个有效的HTML吗?我的直觉是,这是奇怪的用法。但是,也许这是完全正常和有效的?是否在 ul
元素适当的用法中嵌套 div
元素?你会推荐这种方式吗?
它不适用于任何HTML版本。在 ul
HTML 4.01 >。
然而,浏览器允许它解析它,使 div
成为<$ c $的子元素c> ul ,它们让您可以定制 div
。这可能是此标记已被使用的原因。
I'm maintaining a legacy app and came across the following code:
<ul>
<li>...</li>
<li>...</li>
<li>...</li>
<li>...</li>
<li>...</li>
<div>
<li>...</li>
<li>...</li>
</div>
</ul>
I've never seen div
tags as child elements of ul
elements before. The HTML renders fine in browsers.
Is this valid HTML? My gut feeling is that this is strange usage. However, perhaps this is completely normal and valid? Is nesting a div
element inside a ul
element appropriate usage? Would you recommend for or against this?
It is not valid in any version of HTML, see e.g. HTML 4.01 on ul
.
Browsers allow it, though, and parse it so that div
becomes a child of ul
, and they let you style the div
too. This is probably the reason why this markup has been used.
这篇关于允许ul的子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!