内部 CSS 去哪里了?

发布于 2024-11-29 19:12:16 字数 146 浏览 5 评论 0原文

我知道内部 CSS 应该位于 (X)HTML 文档的 部分,但它是否需要位于某些 之前/之后;</code> 元素或者可以是任何顺序吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

琉璃繁缕 2024-12-06 19:12:16

根据 HTML5 规范,非作用域

According to the HTML5 spec, non-scoped <style> elements can go basically anywhere in the <head>.

对岸观火 2024-12-06 19:12:16

没关系。只要它位于头部,它就可以位于所有 标记之前,也可以位于 </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.

放飞的风筝 2024-12-06 19:12:16

head 标签中的元素可以按任意顺序放置。

The elements in the head tag can be placed in any order.

夕嗳→ 2024-12-06 19:12:16

如果没记错的话,任何顺序。但是,我通常经历过在元数据和标题之后的常见做法

Any order, if memory serves. However, I've generally experienced the common practice to be after the meta data and title

中性美 2024-12-06 19:12:16

我假设它以任何顺序都是有效的,但您可以使用以下方式进行确认: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/

情深缘浅 2024-12-06 19:12:16

只要 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文