微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

原文地址:https://www.jb51.cc/html/226105.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐