2017-02-11 68 views
1

我新的軌道,並按照本教程https://launchschool.com/blog/integrating-rails-and-bootstrap-part-1#css_preprocessors,當我通過在最底部加入我不能覆蓋軌道引導CSS與我的自定義CSS

@import "bootstrap-sprockets" 
@import "bootstrap" 

得加引導的一部分application.css.sass它一切都很好。不過,我有代碼

html, body{background:#000;color:#FFF;}

一條線,沒有被尊重。環顧四周後,我意識到,這是因爲我的應用程序文件:

/* 
* 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 any plugin's vendor/assets/stylesheets directory 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 bottom of the 
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 
* files in this directory. Styles in this file should be added after the last require_* statement. 
* It is generally better to create a new file per style scope. 
* 
*= require_tree . 
*= require_self 
*= require custom 
*/ 
@import "bootstrap-sprockets" 
@import "bootstrap" 

我明白,既然「引導」是在最底層,即然而,該網站使用,如果我將它移動到CSS頂部或任何其他地方,我得到一個錯誤頁面。有沒有另外一種方式讓我導入bootstrap或者我來覆蓋頁面?

+0

如果您使用的是** ** SASS然後語法'HTML,身體{背景:#000;顏色:#FFF; ''不適用於一個。您也可以參考Ruby實現的[Bootstrap-SASS](https://github.com/twbs/bootstrap-sass#a-ruby-on-rails)文檔。 – vanburen

+0

我想問你是否有更新。謝謝Fabrizio –

回答

1

我引用https://github.com/rails/sprockets#the-require_self-directive

的require_self指令

require_self告訴鏈輪插入體內的電流源文件的之前任何後續需要指令

這意味着,如果你的require_self然後導入引導,如CSS代表級聯樣式表,在過去的風格總是會被應用加CSS具體的規則。 在以下鏈接閱讀有關css特異性的信息 http://cssspecificity.com/

您可以嘗試設置!important以測試問題是否已解決。另一種方法是包括作爲建議您在一個單獨的文件或CSS代碼SCSS:

*= require_tree . 
*= require_self 
*= require custom 
*/ 
@import "bootstrap-sprockets" 
@import "bootstrap" 
@import "my-css-style" 

如果您還有疑問,請檢查application.css.scss如何在本地主機加載的:3000 /資產/ application.css .scss查看不同樣式表是如何在一個文件中加載的,然後還可以在chrome/firefox上使用debug進行處理,禁用所有樣式,直到找出哪個樣式被覆蓋。

enter image description here