内部 CSS 去哪里了?
我知道内部 CSS 应该位于 (X)HTML 文档的 部分,但它是否需要位于某些
之前/之后;
或
I know that internal CSS should be in the <head></head>
section of a (X)HTML document, but does it need to be before/after certain <meta>
or <title>
elements or can it be any order?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据 HTML5 规范,非作用域
元素基本上可以位于
中的任何位置。
According to the HTML5 spec, non-scoped
<style>
elements can go basically anywhere in the<head>
.没关系。只要它位于头部,它就可以位于所有</code> 和 <code><script>< 之后/代码>s。
标记之前,也可以位于
简而言之:
元素可以位于
元素中的任何位置。
It doesn't matter. As long as it's in the head, it can be before all the
<meta>
tags, or after the<title>
and<script>
s.In short:
<style>
elements can be anywhere in the<head>
element.head 标签中的元素可以按任意顺序放置。
The elements in the head tag can be placed in any order.
如果没记错的话,任何顺序。但是,我通常经历过在元数据和标题之后的常见做法
Any order, if memory serves. However, I've generally experienced the common practice to be after the meta data and title
我假设它以任何顺序都是有效的,但您可以使用以下方式进行确认:W3C 的验证器: http://validator.w3.org /
I assume that it is valid in any order, but you can confirm using: W3C's validator: http://validator.w3.org/
只要 head 标记中的元素不相互依赖(例如,当一个脚本依赖于首先加载的另一个脚本时),顺序并不重要。
在解码文件之前,浏览器将查找包含内容类型和编码的元标记,因此最好将其放在文件的早期。
As long as elements in the head tag doesn't rely on each other (for example when a script relies on another script being loaded first), the order doesn't matter.
The browser will be looking for the meta tag that contains the content type and encoding, before decoding the file, so it's good to have that early in the file.