直接在正文中显示文字 [英] Text directly in body
问题描述
是否允许按照HTML标准将文本直接放置在HTML body
元素中,就像下面的HTML片段一样:
Is it allowed for text to be placed directly in the HTML body
element, by the HTML standards, like in the following piece of HTML:
<body>
Some text
</body>
或者仅允许将文本放置在另一个HTML元素中,例如以下HTML:
Or is it only allowed to place the text in another HTML element, like in the following piece of HTML:
<body>
<p>Some text</p>
</body>
我问这个问题的原因是因为我知道以下内容是无效的HTML 5:
The reason I am asking this is because I know the following is invalid HTML 5:
<body>
<span>Some text</span>
</body>
这是无效的,因为内联元素(如span
)应始终放置在块级元素(如p
)内.因此,对我来说,似乎不太可能允许将文本直接放置在body
中的任何元素之外.
This is invalid because inline elements (like span
) should always be placed inside block level elements (like p
). Therefore, it seems unlikely to me that it would be allowed to place text outside of any elements, directly in the body
.
此外,我们讨论的是哪个版本的HTML标准是否重要?
Also, does it matter which version of the HTML standard we are talking about?
推荐答案
直接在body
元素内的文本是允许的,例如在HTML 4.01 Transitional和HTML5中,但不在HTML 4.01 Strict中.因此,它实际上取决于HTML版本.这实际上只是一种形式;不同的定义仅反映了良好编码风格的不同观点.
Text directly inside the body
element is allowed e.g. in HTML 4.01 Transitional and in HTML5, but not in HTML 4.01 Strict. So it really depends on HTML version. And it is really just a formality; the different definitions reflect just different views of good coding style.
同样适用于像span
这样的内联元素. HTML5中也允许 作为body
的子级.
The same applies to inline elements like span
. They, too, are allowed in HTML5 as children of body
.
这篇关于直接在正文中显示文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!