HAML - 使用 :css 过滤器将 type=text/css 添加到 <style> 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8884316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HAML - add type=text/css to <style> tag with :css filter
提问by Meltemi
I'm trying to add some inline CSS in a HAML file. I thought that
我正在尝试在 HAML 文件中添加一些内联 CSS。我认为
%noscript
:css
.pagecontent {display:none;}
would produce:
会产生:
<noscript>
<style type="text/css">
/*<![CDATA[*/
.pagecontent {display:none;}
/*]]>*/
</style>
</noscript>
but it doesn't. As it leaves out the type="text/css"
and produces:
但事实并非如此。因为它省略了type="text/css"
和 产生:
<noscript>
<style>
/*<![CDATA[*/
.pagecontent {display:none;}
/*]]>*/
</style>
</noscript>
I could just use brute force %style(type="text/css")
but HAML's :css
filter seems like it shouldbe more "elegant"?!? Or, did I miss something (I rarely deal with inline CSS) and type
is no longer necessary?!?
我可以只使用蛮力,%style(type="text/css")
但 HAML 的:css
过滤器似乎应该更“优雅”?!?或者,我是否错过了一些东西(我很少处理内联 CSS)并且type
不再需要?!?
采纳答案by matt
Haml will output the type
attribute if the format
option is set to xhtml
or html4
. If the format is set to html5
the attribute will be omitted.
type
如果format
选项设置为xhtml
或 ,Haml 将输出属性html4
。如果格式设置html5
为该属性将被省略。
See the Haml docs on optionsand the source of the CSS filter.
The default in Haml 3.1.x is xhtml
, except in Rails when it is html5
since that is the Rails default. In Haml 4+ the default will be html5
throughout. (Also in 4+ the CDATA tags will be left out by default when the format is html4
or html5
.)
Haml 3.1.x 中的默认值是xhtml
,但在 Rails 中除外,html5
因为这是 Rails 的默认值。在 Haml 4+ 中,默认值将html5
贯穿始终。(同样在 4+ 中,当格式为html4
或时,默认情况下 CDATA 标签将被省略html5
。)
回答by Domenic
type
defaults to text/css
as of HTML5, and has always done so in practice (i.e. in browser implementations).
type
默认text/css
为 HTML5,并且在实践中一直这样做(即在浏览器实现中)。
So yes, type="text/css"
is not necessary (and never has been).
所以是的,type="text/css"
没有必要(而且从来没有)。