HAML - 使用:css filter </style>将type = text / css添加到<style>标记

时间:2012-01-16 18:05:40

标签: css haml sass noscript

我正在尝试在HAML文件中添加一些内联CSS。我以为

%noscript
  :css
    .pagecontent {display:none;}

会产生:

<noscript>
  <style type="text/css">
    /*<![CDATA[*/
      .pagecontent {display:none;}
    /*]]>*/
  </style>
</noscript>

但事实并非如此。因为它遗漏了type="text/css"并产生:

<noscript>
  <style>
    /*<![CDATA[*/
      .pagecontent {display:none;}
    /*]]>*/
  </style>
</noscript>

我可以使用蛮力%style(type="text/css"),但HAML的:css过滤器似乎应该更“优雅”?!?或者,我错过了什么(我很少处理内联CSS)并且不再需要type?!

2 个答案:

答案 0 :(得分:20)

如果type选项设置为formatxhtml,则Haml将输出html4属性。如果格式设置为html5,则将省略该属性。

请参阅Haml docs on optionssource of the CSS filter

Haml 3.1.x中的默认值为xhtml,但Rails中的默认值为html5,因为这是Rails的默认值。在Haml 4+中,默认值为html5。 (当格式为html4html5时,默认情况下,CD +标签也将被排除在4+以外。)

答案 1 :(得分:9)

type defaults to text/css as of HTML5,并且在实践中一直这样做(即在浏览器实现中)。

所以是的,type="text/css"没有必要(而且从来没有)。