简体   繁体   English

css at-rule在样式属性中是否有效?

[英]Is it valid for css at-rule to be in style attribute?

Is the following markup valid? 以下标记是否有效?

<!DOCTYPE html>
<html>
    <head>
         <title>Test whether at-rules are valid in style attributes</title>
    </head>
    <body style="@import url(style.css);"></body>
</html>

Firefox and Chromium on Linux don't render it, but the W3C validator did not mark it as an error. Linux上的Firefox和Chromium不会渲染它,但W3C验证器没有将其标记为错误。

No. 没有。

Only a declaration may be placed inside a style attribute. 只有声明可以放在样式属性中。

From the HTML 4.01 specification : HTML 4.01规范

The syntax of the value of the style attribute is determined by the default style sheet language. style属性值的语法由默认样式表语言确定。 For example, for [[CSS2]] inline style, use the declaration block syntax described in section 4.1.8 (without curly brace delimiters). 例如,对于[[CSS2]]内联样式,请使用4.1.8节(没有大括号分隔符)中描述的声明块语法。

It is not. 它不是。

@ -rules can't contain rules directly, but only selectors. @ -rules不能直接包含规则,只能包含选择器。

  • @import imports a file, but they can't have rules outside selectors. @import导入一个文件,但它们不能有选择器之外的规则。
  • @media can only contain selectors. @media只能包含选择器。
  • @font-face doesn't affect elements. @font-face不会影响元素。

The style attribute is meant for setting rules directly to elements, so clearly the @ -rules don't fit to that. style属性用于直接将规则设置为元素,因此@ -rules显然不适合。

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

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