【问题标题】:Rails CSS CompilingRails CSS 编译
【发布时间】:2013-12-09 20:58:24
【问题描述】:

我最近为一个 rails 应用程序运行了 bundle install,它在我的供应商文件夹中放置了一个 ruby​​ 文件夹,其中包含 bin、cache、doc、gem 等。

自那以后,我的 CSS 样式似乎遇到了冲突。我正在使用引导程序和覆盖文件,但是在我的样式混乱的地方,我注意到检查元素时在奇怪的地方出现 :before 和 :after 。

某些元素似乎失去了样式,但其他元素看起来还不错。我猜我的样式在某个地方被覆盖了,但我不明白它是怎么发生的。

谁能帮助我了解如何在未来解决和避免这种情况?看起来我的供应商文件夹可能会覆盖我实现的样式。

我的应用程序.css.scss

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* 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 font-awesome
*= require bootstrap_and_overrides
*/

【问题讨论】:

    标签: css ruby-on-rails asset-pipeline


    【解决方案1】:

    将 require_self 移到清单文件的最后一行。

    【讨论】:

    • 我尝试了这个并且结果相同 - 失去了一些样式。感谢您的建议。
    【解决方案2】:

    所以,基本上 CSS 覆盖就是这样发生的

    1) 最后一个获胜 2) 更具体的 CSS 选择器获胜(无论它在哪里定义)

    因此,如果您为 bootstrap 打补丁,请确保将它们放在 您包含 bootstrap 本身之后,其次尝试使用更具体的 CSS 选择器,比如使用您的应用特定的 css 类名称和东西像这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-10
      • 2017-06-03
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 2014-11-07
      相关资源
      最近更新 更多