微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html5 – 什么时候结束不是可选的?

W3 says

An li element’s end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.

但是这个:

<ol>
    <li>one
    <li>two
    <li>three
        <ol>
            <li>three.one
            <li>three.two
        </ol>
    <li>four
</ol>

出现在render fine.

我不知道四个人的李是否被认为是“紧跟三个人”,因为中间有一个人.规范并不是很清楚 – 从技术上讲,文本“one”代表一个TextNode,所以两个人的li并不是真正紧随其后.

实际上是否有任何关闭< / li>的情况有必要的?

我只安装了Chrome和Firefox,但它们都能实现我的预期.

据我所知,ul和ol唯一合法的直接子女是李,所以不能有任何歧义,对吧?

解决方法

那么,W3C所说的是什么

An li element’s end tag is mandatory if the li element is immediately followed by something else than another li element or if there is more content in the parent element.

这怎么可能? li元素可以在ols,uls和菜单中使用only occur.
但ols und uls只允许lis作为他们的孩子.

菜单怎么样?它也是allows flow content.所以你有它:

<menu>
    <li>foo</li> <!-- mandatory -->
    <a href="//example.com">bar</a>
</menu>

<menu>
    <li>foo</li> <!-- mandatory -->
    Hello,I am text content!
</menu>

当您看到示例时,很明显省略结束标记会使解析器无法确定li结束的位置.

编辑:正如@BoltClock指出的那样,现在也允许脚本和模板元素:

<ul> <!-- or ol or menu -->
    <li>foo</li> <!-- mandatory -->
    <script></script>
</ul>

原文地址:https://www.jb51.cc/html5/241012.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。