【问题标题】:Rails 3.1 Load css in particular orderRails 3.1按特定顺序加载css
【发布时间】:2012-02-12 00:55:46
【问题描述】:

我看到在 rails 3.1 的开发环境中,css 是按字母顺序加载的,而不是按我想要的顺序加载的。我希望一个特定的 css 文件位于末尾,因此它会覆盖之前给该类的任何样式。我们怎样才能做到这一点?

【问题讨论】:

  • 最简单的技巧是重命名它。 zzz-the_last.css
  • 我现在也这样做了!!!但这是一个黑客!有 Rails 方式吗?

标签: ruby-on-rails css ruby-on-rails-3.1


【解决方案1】:

您实际上可以执行以下操作:

/* 
 *= require 'reset'
 *= require_self
 *= require_tree .
*/

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

不尝试复活旧线程,只是认为这可能对某些人有所帮助。

【讨论】:

  • 这似乎也删除了该文件在链中稍后再次加载(以防止双重加载),至少在 Rails 4 中。
【解决方案2】:

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

/*
 * 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
*

【讨论】:

  • 加载下面的树会发生什么? = 要求树。 ?
  • 所以我自己在需要样式表的地方加载,然后按我的顺序得到它。对吗?
  • 但这是给出错误 *= 需要重置 *= 需要组 *= 需要 the_last //这会抛出错误,例如:“找不到文件 'the_last'”
  • 您需要将 resetgroupsthe_last 更改为您的 css 文件的名称 - 这只是一个展示其工作原理的示例。
猜你喜欢
  • 2015-03-18
  • 2016-08-23
  • 1970-01-01
  • 1970-01-01
  • 2017-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多