如何在rails

时间:2017-06-03 19:04:44

标签: css ruby-on-rails bulma

我正在使用bulma rails gem,我想自定义它使用的一些变量,特别是字体颜色。

根据bulma docs http://bulma.io/documentation/overview/customize/我应该这样做:

// 1. Import the initial variables
@import "../sass/utilities/initial-variables"

// 2. Set your own initial variables
// Update blue
$blue: #72d0eb
// Add pink and its invert
$pink: #ffb3b3
$pink-invert: #fff
// Add a serif family
$family-serif: "Merriweather", "Georgia", serif

// 3. Set the derived variables
// Use the new pink as the primary color
$primary: $pink
$primary-invert: $pink-invert
// Use the existing orange as the danger color
$danger: $orange
// Use the new serif family
$family-primary: $family-serif

// 4. Import the rest of Bulma
@import "../bulma"

但是我不知道如何使用我正在使用的rails gem。

目前我的application.css文件如下所示:

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

@import "bulma";

工作正常。但是,如果我将其更改为与bulma文档中的示例相同,即使将@import "../bulma"更改为@import "bulma"并将@import "../sass/utilities/initial-variables" 更改为@import "sass/utilities/initial-variables"

,它也不再有效

我想这里的问题是首次导入变量,但我无法弄清楚如何导入它。这是gem中的文件:https://github.com/joshuajansen/bulma-rails/blob/master/app/assets/stylesheets/sass/utilities/variables.sass

谢谢!

2 个答案:

答案 0 :(得分:9)

好的,设法让这个工作。

我在application.css.scss目录中创建了一个名为app/assets/stylesheets的文件,并添加了以下内容:

$blue: #72d0eb;
$pink: #ffb3b3;
$pink-invert: #fff;
$family-serif: "Merriweather", "Georgia", serif;
$primary: $pink;
$primary-invert: $pink-invert;
$family-primary: $family-serif;

@import "bulma";

这很好用。添加初始导入语句会导致失败,但有点尝试使路径正确,但它总是失败。不确定这是否有任何意义,我没有看到,但现在无论如何都适合我。

答案 1 :(得分:3)

在我的情况下,application.css已经存在,并且关注looneym的答案并不起作用。事实证明,我只需要重命名" application.css"到" application.css.scss",然后我可以改变一些变量如下:

/* Use Bulma for styling */
$green: #00E676;
$primary: $green;
@import "bulma";

要在RubyMine中执行此操作,只需右键单击树中的文件,选择" refactor"然后"重命名"。