Overriding Bootstrap variables in Rails with bootstrap-sass gem Overriding Bootstrap variables in Rails with bootstrap-sass gem ruby-on-rails ruby-on-rails

Overriding Bootstrap variables in Rails with bootstrap-sass gem


You can override variables by simply redefining the variable before the @import directive.

For example:

$navbar-default-bg: #312312;$light-orange: #ff8c00;$navbar-default-color: $light-orange;@import "bootstrap";


see the execution cycle. in the bootstrap file, files rendering in this manner such us "get variable > and apply in navbar" this really happen when started to execute the bootstrap file. Its present inside of the bootstrap, look the sequential flow of importing . , the variable are getting from bootstrap/variables and setting up the vavbar color in bootstrap/navbar, this applying the color in navbar with the variable navbar-default-bg.

what actually programmers are doing is trying to setup the variable value after setting up the color in navbar. (before or after "@importing bootstrap" statement,the variable changes will not make changes in the navbar color, need to edit in the bootstrap file)

look into the code below if you want to change the color you have to do the following.

inside bootstrap file

// Core variables and mixins

@import "bootstrap/variables";

// Components

@import "bootstrap/navs";

$navbar-default-bg:red; // initialize the $navbar-default-bg (after importing bootstrap/variables)

@import "bootstrap/navbar"; here the color setting is performing"

this will work fine, analyze the execution cycle.

but I am suggesting use the other manual classes for applying the bg-color instead of over riding bootstrap variable.

Ref : https://github.com/RailsApps/rails-bootstrap/issues/12