Rails 3.1按特定顺序加载css

pho*_*ard 25 css ruby-on-rails ruby-on-rails-3.1

我看到在rails 3.1的开发环境中,css是按字母顺序加载的,而不是按照我想要的顺序加载.我想要一个特定的css文件在最后,所以它覆盖之前给予类的任何样式.我们怎样才能做到这一点?

小智 40

你实际上可以这样做:

/* 
 *= require 'reset'
 *= require_self
 *= require_tree .
*/
Run Code Online (Sandbox Code Playgroud)

在您的application.css文件中.这允许您在树之前指定任意数量的样式表(例如重置),而无需指定每个单独的文件.复位周围的单引号是可选的.

不试图复活一个旧线程,只是认为这可能对某些人有所帮助.

  • 看来这也会删除该文件以后在链中再次加载(以防止双重加载),至少在Rails 4中. (5认同)

Aru*_*nan 18

最好手动指定每个文件的顺序:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require reset
 *= require groups
 *= require the_last
*
Run Code Online (Sandbox Code Playgroud)

  • 你需要用你的css文件的名字来改变`reset`,`groups`和`the_last` - 这只是一个展示它如何工作的例子. (4认同)