两个代码都完全有效,但是哪个在语义上是正确的?

发布于 2024-10-08 02:40:03 字数 809 浏览 7 评论 0原文

两个代码都完全有效,但是哪个在语义上是正确的?

它有

<ol>
    <li>
        <h2>heading level 2</h2>
          <p>
             some long text here some long text here some long text 
             here some long text here some long text here some long 
             text here some long text here some long text here
         </p>
    </li>
</ol>

这是没有

<ol>
    <li>
        <h2>heading level 2</h2>

           some long text here some long text here some long 
           text here some long text here some long text here 
           some long text here some long text here some long text here
    </li>
</ol>

Both code are perfectly valid , but which is semantically correct?

It has <p>

<ol>
    <li>
        <h2>heading level 2</h2>
          <p>
             some long text here some long text here some long text 
             here some long text here some long text here some long 
             text here some long text here some long text here
         </p>
    </li>
</ol>

This is without <p>

<ol>
    <li>
        <h2>heading level 2</h2>

           some long text here some long text here some long 
           text here some long text here some long text here 
           some long text here some long text here some long text here
    </li>
</ol>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〆凄凉。 2024-10-15 02:40:03

这取决于文本是否是段落。可能是,但很难从占位符内容中看出。

(这假设将内容作为有序列表项在语义上首先是正确的。)

That depends on if the text is a paragraph or not. It probably is, but it is hard to tell from the placeholder content.

(This assumes that having the content as an ordered list item is semantically correct in the first place.)

祁梦 2024-10-15 02:40:03

最好使标记与网站易于关联。因此,我选择

版本,以便我的代码的读者可以更轻松地了解网站的结构。

It's best to keep the markup easily associable with the website. Therefore, I'd choose the <p> version so readers of my code could more easily follow the website's structure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文