سؤال

I'm trying to add some inline CSS in a HAML file. I thought that

%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:

<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 should be more "elegant"?!? Or, did I miss something (I rarely deal with inline CSS) and type is no longer necessary?!?

هل كانت مفيدة؟

المحلول

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.

See the Haml docs on options and 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.)

نصائح أخرى

type defaults to text/css as of HTML5, and has always done so in practice (i.e. in browser implementations).

So yes, type="text/css" is not necessary (and never has been).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top