我正在尝试在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
?!
答案 0 :(得分:20)
如果type
选项设置为format
或xhtml
,则Haml将输出html4
属性。如果格式设置为html5
,则将省略该属性。
请参阅Haml docs on options和source of the CSS filter。
Haml 3.1.x中的默认值为xhtml
,但Rails中的默认值为html5
,因为这是Rails的默认值。在Haml 4+中,默认值为html5
。 (当格式为html4
或html5
时,默认情况下,CD +标签也将被排除在4+以外。)
答案 1 :(得分:9)
type
defaults to text/css
as of HTML5,并且在实践中一直这样做(即在浏览器实现中)。
所以是的,type="text/css"
没有必要(而且从来没有)。