HTML“空白元素”所谓的因为没有内容? [英] HTML "void elements" so called because without content?

查看:204
本文介绍了HTML“空白元素”所谓的因为没有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据W3C Void元素不能有任何内容(,因为没有结束标签,内容不能放在开始标签和结束标签之间)

但是,在我看来,html元素不需要结束标记有内容(例如: td th tr TAG:对于这些,结束标记是可选的,并且在任何情况下都是隐含的,但不要让他们无效)。
简而言之,HTML void 元素是(真的)元素?
鉴于区别于html元素normal的唯一区别是它们没有结束标记,最好是调用mono-tag吗?

However, it seems to me that the end-tag is not required for an html element has a content (eg: td or th or tr TAG: for these, the end-tag is optional and -in any case- implicit, but does not make them "void"). In short, HTML "void" elements are (really) "empty" elements? Given that the true and only difference that distinguishes them from html elements "normal" is that they have no closing tag, it would be better to call mono-tag?

如果这个地方不适合提出这样的问题,我很抱歉。

I apologize if this place was not the right one to ask questions like that.

感谢您的时间。

<table>
  <tr>
    <th>1
    <th>2
  </tr>
  <tr>
    <td>3
    <td>4
  </tr>
</table>


推荐答案


简而言之,HTML void元素是(真的)空元素?

In short, HTML "void" elements are (really) "empty" elements?

更确切地说,void元素是不能有内容。也就是说,一个void元素是一个只有且总是空的元素。此外,void元素不能具有结束标记 - 结束标记不是可选,它是禁止。这意味着< br>< / br> < img src =example.png>< / img> 都是无效HTML。

To be more precise, a void element is an element that cannot have content. That is, a void element is an element that is only and always empty. Furthermore, a void element cannot have an end tag — the end tag isn't optional, it's forbidden. Which means <br></br> and <img src="example.png"></img> are both invalid HTML.

具有可选结束标记的元素,如 tr th td 可以包含内容,因此不是void元素。但是,它们可以是空的,例如这里的 th td 元素:

Elements with optional end tags such as tr, th and td can have content and are therefore not void elements. They can, however, be empty, such as the th and td elements here:

<table>
  <tr><th><th></tr>
  <tr><td><td></tr>
</table>

参见:无效元素和空元素是否相同?

这篇关于HTML“空白元素”所谓的因为没有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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