【问题标题】:HAML - add type=text/css to <style> tag with :css filterHAML - 使用 :css 过滤器将 type=text/css 添加到 <style> 标记
【发布时间】:2012-02-11 15:33:39
【问题描述】:

我正在尝试在 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?!?

【问题讨论】:

    标签: css haml sass noscript


    【解决方案1】:

    如果format 选项设置为xhtmlhtml4,Haml 将输出type 属性。如果格式设置为html5,该属性将被省略。

    请参阅Haml docs on optionssource of the CSS filter

    Haml 3.1.x 中的默认值是xhtml,除了在 Rails 中它是 html5,因为这是 Rails 的默认值。在 Haml 4+ 中,默认值为 html5。 (同样在 4+ 中,当格式为 html4html5 时,默认情况下会省略 CDATA 标签。)

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 2013-03-12
      相关资源
      最近更新 更多