CSS require Syntax

[亡魂溺海] 提交于 2020-02-03 06:23:26

问题


I have required CSS stylesheets many times in many of my RubyOnRails applications, and actually i need a few things demystified.

What is the difference between:

//=require mystyles

and

*=require mystyles

Both seem to work, so what is the difference?

And is this a part of the asset pipeline or a part of SASS or just plain CSS?


回答1:


The two examples you gave are exactly the same for stylesheets, however the //= syntax is the only one that works for Javascript. You also need a standard CSS comment at the start (/*) and a close comment (*/) at the end of the require block to make it ignored to anything but the asset pipeline:

/* ...
*= require mystyles
*= require_self
*/

These require directives are only part of the asset pipeline, not CSS or SASS. To include a stylesheet for CSS or SASS, you would use a @import rule as Blieque stated in his comment.

Check out the manifest files and directives section of the Asset Pipeline guide on the Ruby on Rails guide site for a more detailed explanation of the difference. There is also a warning given there that might be of interest:

If you want to use multiple Sass files, you should generally use the Sass @import rule instead of these Sprockets directives. Using Sprockets directives all Sass files exist within their own scope, making variables or mixins only available within the document they were defined in.




回答2:


There is no difference, as long as it's a valid comment line, it'll work :)



来源:https://stackoverflow.com/questions/20294823/css-require-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!