简体   繁体   English

<style> tag within body and W3 Standards

[英]<style> tag within body and W3 Standards

After reading this question I am confused: 看完这个问题我很困惑:

Using <style> tags in the <body> with other HTML 在<body>中将<style>标记与其他HTML一起使用

Most people in there say it is bad practice to have style tags in the body section, and that it does not adhere to W3 standards, however I read this differently: 那里的大多数人说,在主体部分中包含样式标签是不好的做法,并且它不符合W3标准,但是我的理解有所不同:

http://www.w3.org/TR/html-markup/style.html#style http://www.w3.org/TR/html-markup/style.html#style

Above link says: 上面的链接说:

Permitted parent elements:
Any element that can contain metadata elements, div, noscript, section, article, aside

The body element allows all these apart from 'metadata elements', but this list does not state that all of these elements need to be accepted in order for the style tag to be allowed. 除了“元数据元素”之外,body元素还允许所有这些元素,但是此列表并未声明必须接受所有这些元素才能允许样式标签。 So surely it is OK by W3 standards to have the style tag within the body simply because for example the body element allows the use of div? 因此,按W3标准肯定可以在主体中包含样式标签,这仅仅是因为例如body元素允许使用div?

Maybe I'm reading this much later (5 years on) and this rule has been changed because of the 'scoped' attribute for style tags, so I wanted to ask to see if I was wrong in my interpretation of their standard or not. 也许我是在以后(5年后)阅读此书,并且由于样式标签的“作用域”属性而更改了此规则,所以我想问一下我在解释其标准时是否错了。

From the front page of the document you linked to: 从链接到的文档首页

This document has been discontinued and is only made available for historical purposes. 该文档已停产,仅可用于历史目的。 For an up to date reference on HTML elements (and more) please consult Web Platform Docs. 有关HTML元素(及更多内容)的最新参考,请查阅Web平台文档。

Some draft versions of HTML 5 allowed style elements in the body under certain conditions . 在某些情况下 ,HTML 5的某些草稿版本允许在正文中使用样式元素。

There were various problems with the design of that functionality and it did not make it into the final version of HTML 5. 该功能的设计存在各种问题,但并未纳入HTML 5的最终版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM