CSS必须在< head>标签? [英] Does CSS have to be defined within <head> tags?

查看:141
本文介绍了CSS必须在< head>标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的页面中定义一个CSS片段,如下所示:

I would like to define a snippet of CSS in my page like this:

<style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
</style>



我继续阅读,应该定义在< head> / code>元素,但它似乎工作正常时内联。

I keep reading that it should be defined within the <head> element, but it seems to work fine when inline. Can someone confirm if this is okay?

推荐答案

对于HTML 4,规范说:

For HTML 4 the spec says:


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.

参考资料: http://www.w3.org/TR/html4/present/styles.html#h-14.2.3

他们对文档的规定,而不是简单的文档强烈暗示其他地方是不适当的。

Their specification of "head of the document", rather than simply 'document' strongly suggests that elsewhere is inappropriate.

但是,对于HTML 5,这是放松的,并且 style 元素可以放置在文档本身中:

For HTML 5, however, this is relaxed and the style element can be placed within the document itself:


样式元素允许作者在其文档中嵌入样式信息。样式元素是样式处理模型的几个输入之一。该元素不代表用户的内容。

The style element allows authors to embed style information in their documents. The style element is one of several inputs to the styling processing model. The element does not represent content for the user.

参考资料: http:// www .w3.org / TR / html5 / semantics.html#the-style-element

这篇关于CSS必须在&lt; head&gt;标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆