为什么< p>标签包含< div>里面的标签?

编程入门 行业动态 更新时间:2024-10-25 12:23:07
本文介绍了为什么< p>标签包含< div>里面的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

据我所知,这是正确的:

As far as I know, this is right:

<div> <p>some words</p> </div>

但这是错误的:

<p> <div>some words</div> </p>

第一个可以通过 W3C验证器(XHTML 1.0),但第二个则不能.我知道没有人会像第二个那样编写代码.我只想知道为什么.

The first one can pass the W3C validator (XHTML 1.0), but the second can't. I know that nobody will write code like the second one. I just want know why.

那其他标签的收容关系又如何呢?

And what about other tags' containment relationship?

推荐答案

HTML规范是寻找允许的收容关系的权威之地.参见例如 www.w3/TR/html4/sgml/dtd.html .它指定哪些元素是块元素,哪些是内联元素.对于这些列表,搜索标记为"HTML内容模型"的部分.

An authoritative place to look for allowed containment relations is the HTML spec. See, for example, www.w3/TR/html4/sgml/dtd.html. It specifies which elements are block elements and which are inline. For those lists, search for the section marked "HTML content models".

对于P元素,它指定以下内容,这表明P元素只允许包含内联元素.

For the P element, it specifies the following, which indicates that P elements are only allowed to contain inline elements.

<!ELEMENT P - O (%inline;)* -- paragraph -->

这与 www一致. w3/TR/html401/struct/text.html#h-9.3.1 ,其中指出P元素不能包含块级元素(包括P本身)."

This is consistent with www.w3/TR/html401/struct/text.html#h-9.3.1, which says that the P element "cannot contain block-level elements (including P itself)."

更多推荐

为什么&lt; p&gt;标签包含&lt; div&gt;里面的标签?

本文发布于:2023-11-13 06:37:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   lt   amp   div   gt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!