gpt4 book ai didi

html -

标签什么时候被认为是空的?

转载 作者:搜寻专家 更新时间:2023-10-31 08:04:01 26 4
gpt4 key购买 nike

W3.org states :

We discourage authors from using empty P elements.

User agents should ignore empty P elements.

我们如何定义

<p> </p> 之间是否有空格字符标签算不算?

<p> </p> 之间的换行符呢? ?

最佳答案

The HTML4 spec defines an empty element as one that has no content.自闭合标签明确定义空元素,如 <br/><img/> .我认为期望开始标记后紧跟结束标记是非常合理的,例如 <p></p>还定义了一个空元素。是否<p> </p>是否符合“空”的条件可能取决于用户代理,但让我们看看 the inline content model definition from the spec:

<!-- %inline; covers inline or "text-level" elements -->
<!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;">

“空”内容是指不包含以下内容的:

那么空格字符是上面的任何一个吗? Yes, it's #PCDATA ,所以我可以推断出 <p> </p> 不是一个空的 P元素。不管 HTML4 规范如何劝阻, <p></p> , <p> </p> , and <p/> are all a perfectly valid HTML fragments .


Such elements are now called "void" by the HTML5 spec.

@Alohci clarifies:

The term "void elements" in HTML5 refers to those element types whose instances can never have content like br and img, not to instances that happen to have no content. So instances of P elements never constitute a "void element."

HTML5 规范没有关于避免“空”或“空”的评论P元素:

...我真的不会太担心。

关于html - <P> 标签什么时候被认为是空的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15216248/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com