< STYLE>必须在< HEAD>的HTML文档? [英] Does <STYLE> have to be in the <HEAD> of an HTML document?
问题描述
严格地说, style
标签需要在HTML文档的 head
中? 4.01标准意味着,但它没有明确说明:
Strictly speaking, do style
tags need to be inside the head
of an HTML document? The 4.01 standard implies that, but it's not explicitly stated:
STYLE元素允许作者
将样式表规则放在头
的文件。 HTML允许文档的HEAD部分
中的任何数字
的STYLE元素。
The STYLE element allows authors to put style sheet rules in the head of the document. HTML permits any number of STYLE elements in the HEAD section of a document.
说,因为我有一个应用程序将样式元素放在身体内,所有我测试的浏览器似乎使用样式元素。我只是想知道这是否合法。
I say "strictly speaking" because I have an app that puts style elements inside the body, and all the browsers I've tested with seem to use the style elements. I'm just wondering if that's actually legal.
推荐答案
style
应该仅包含在文档的头
上。
style
is supposed to be included only on the head
of the document.
除了验证点之外,在上使用
是 flash of untyled content 。浏览器将获得在之后被显示的样式的元素,使它们在大小/形状/字体和/或闪烁上移位。它通常是不好的工艺的标志。一般来说,你可以随意放置 style
body style
到任何你想要的地方,但是尽可能避免它。
Besides the validation point, one caveat that might interest you when using style
on the body
is the flash of unstyled content. The browser would get elements that would be styled after they are displayed, making them shift on size/shape/font and/or flicker. It is generally a sign of bad craftsmanship. Generally you can get away with putting style
anywhere you want, but try to avoid it whenever it is possible.
HTML 5引入了一个 scoped
属性,允许 style
标签被包括在主体的任何地方, 。
HTML 5 introduced a scoped
attribute that allowed style
tags to be included everywhere in the body, but then they removed it again.
这篇关于< STYLE>必须在< HEAD>的HTML文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!