是否正确使用< style> < head>之外的标签元件? [英] Is it correct to use the <style> tag outside of the <head> element?
问题描述
使用< style> < head>之外的标签元素?
像这样:
< html>
< head>
< style>一些风格< / style>
< / head>
< body>一些文字< / body>
< style>更多风格< / style>
< body>一些更多的文字< / body>
< / html>
我想这样做是因为:我的cgi以其自己的样式来源其他文件。
cgi文件包含:
#!/ bin / bash
echocontent-type:text / html
echo
echo< html>< head>< style>
echoh1 {color:red;}
echo< / style>
回声< body>
在这里回显< h1>一些文字< / h1>
回声< / body>
源./data.sh
回声< / html>
源文件包含:
echo< style>
echoh2 {color:blue;}
echo< / style>
回声< body>
回声< h2>以及其他一些文字< / h2>
回声< / body>
这似乎工作正常。但它是否正确?
在w3schools中它说:
每个HTML文档可以包含多个< style> Tags
$ b但是这样做了吗?
style应该只包含在文档的头部。
除了验证点之外,在身体上使用样式时可能会引起您的一个警告是未格式化内容的闪烁。浏览器会在显示后显示样式的元素,使它们在大小/形状/字体和/或闪烁上移动。这通常是工艺不好的一个标志。通常情况下,您可以随时随地放置样式,但只要有可能就尽量避免。
HTML 5引入了允许包含样式标签的范围属性根据W3规范,< link>
标签只应该放在< head>
部分中: $ b
参考
对于HTML 4.01: http: //www.w3.org/TR/html401/struct/links.html#edef-LINK
对于HTML5: http://www.w3.org/TR/html5/document-metadata.html #$链接元素
验证问题
如果您将标签放在身体内的HTML文件,它不会使用validate.w3.org
进行验证
Is it correct to use the <style> tag outside of the <head> element ?
Like this:
<html>
<head>
<style> some style </style>
</head>
<body> some text </body>
<style> some more style </style>
<body> some more text </body>
</html>
I want to do this because: my cgi sources other files with their own style.
The cgi file contains:
#!/bin/bash
echo "content-type: text/html"
echo ""
echo "<html><head><style>"
echo "h1 {color: red;}"
echo "</style>"
echo "<body>"
echo "<h1> some text here </h1>"
echo "</body>"
source ./data.sh
echo "</html>"
And the source file contains:
echo "<style>"
echo "h2 {color: blue;}"
echo "</style>"
echo "<body>"
echo "<h2> and some other text here </h2>"
echo "</body>"
This seems to work fine. But is it correct ?
At w3schools it says:
Each HTML document can contain multiple <style> tags.
But is it done this way ?
style is supposed to be included only on the head of the document.
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 introduced a scoped attribute that allowed style tags to be included everywhere in the body, but then they removed it again.
According to the W3 specs, <link>
tags are only supposed to go in the <head>
section:
References
For HTML 4.01: http://www.w3.org/TR/html401/struct/links.html#edef-LINK
For HTML5: http://www.w3.org/TR/html5/document-metadata.html#the-link-element
Validation Issues
If you put a tag within the body of the HTML document, it will not validate using validate.w3.org
这篇关于是否正确使用< style> < head>之外的标签元件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!