我想在我的页面中定义一个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.