如果标题是在< p>之内或之外的? [英] Should a heading be inside or outside a <p>?

查看:136
本文介绍了如果标题是在< p>之内或之外的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div元素,在该div内,我们在p元素之间有文本。

I have a div element and within that div, we have text between p elements.

我想添加一个标题。它应该在内部还是外部?

I want to add a heading. Should it go inside or outside the p?

哪个更好:

Which is better:

<p>This is text
    <h3>This is my h3</h3>
    More text
</p>
<p>another text<p>

<p>This is text<p>
<h3>This is my h3</h3>
<p>another text<p>


推荐答案

HTML标记中的code> p 元素,不仅仅是形式上的,而是因为浏览器在遇到标题时隐式地终止一个打开的 p 元素。所以这个问题是没有意义的:一个不能存在于某个上下文中的元素在这个上下文中不会有任何意义(语义)。

It is impossible to put a heading element inside a p element in HTML markup, not just formally but because browsers implicitly terminate an open p element when they encounter a heading. So the question is meaningless: an element that cannot exist in a certain context cannot have any meaning (semantics) within that context.

不是使用你可以使用 div 元素,或者像常见的注意事项一样使用HTML5新颖的元素,比如部分文章

Instead of using p to group text and headings together, you can use the div element or, with the usual caveats, HTML5 novelties like section and article.

这篇关于如果标题是在&lt; p&gt;之内或之外的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆