[英]Is body element a block-level or in-line element?
I've looked on the MDN for any indication whether the HTML body element is a block-level or inline-level element: 我已经在MDN上查看了HTML body元素是块级元素还是内联级元素的任何指示:
Inline Elements / Block-level Elements 内联元素 / 块级元素
Neither of these mentions anything about the body element except: 这些都没有提及身体元素的任何内容,除了:
Block-level elements may appear only within a < body > element.
块级元素可能仅出现在<body>元素中。
W3 defined it as a block. W3将其定义为块。 http://www.w3.org/TR/html401/struct/global.html#edef-BODY
http://www.w3.org/TR/html401/struct/global.html#edef-BODY
It is displayed as a block by default. 它默认显示为块。 http://www.w3.org/TR/html-markup/body.html
http://www.w3.org/TR/html-markup/body.html
HTML4 classified elements into the "block-level" and "inline" categories. HTML4将元素分类为“块级”和“内联”类别。
However, HTML5 doesn't have that notion. 但是,HTML5没有这个概念。 Instead, it was moved to CSS: block-level elements and block boxes and inline-level elements and inline boxes .
相反,它被移动到CSS: 块级元素和块框以及内联级元素和内联框 。
According to HTML5, the body
element belongs to the sectioning root category. 根据HTML5,
body
元素属于sectioning根类别。 And that's all. 就这样。
However, in Rendering - The page , HTML5 specifies that body
should be displayed as a block by default: 但是,在Rendering - 页面中 ,HTML5指定默认情况下应将
body
显示为块:
html, body { display: block; }
Then, according the the definition in CSS, it will be block-level, unless you override that style. 然后,根据CSS中的定义,它将是块级别,除非您覆盖该样式。
As a rule of thumb (aka. how HTML4 did it): Since it can't just hold text but also block elements, it's a block element. 根据经验(也就是HTML4是如何做到的):因为它不仅可以保存文本而且还可以阻止元素,因此它是一个块元素。
There are now some exceptions since HTML5 was introduced though, like being allowed to wrap anchors around pretty much anything. 自从HTML5被引入以来,现在有一些例外,比如允许将锚点包装在几乎任何东西周围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.