HTML – 是否必须在标签内定义CSS?

我想在我的页面中定义一个CSS片段,如下所示:
<style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
</style>

我一直在读它应该在< head>中定义它.元素,但内联时似乎工作正常.有人可以确认这是否可以?

解决方法

对于HTML 4规范说:

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.

Reference: http://www.w3.org/TR/html4/present/styles.html#h-14.2.3.

他们对“文件负责人”的说明,而不仅仅是“文件”强烈暗示其他地方是不合适的.

但是,对于HTML 5,这是放松的,样式元素可以放在文档本身中:

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.

Reference: http://www.w3.org/TR/html5/semantics.html#the-style-element.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些