knagode
knagode

Reputation: 6125

How to reuse (extend) bootstrap css classes in rails/sass

I @import "boostrap" in core.scss file which also import other scss files (e.g.: _modals.css).

In modals.css I want to extend some bootstrap classes:

.modal-container {
  @extend .row;
}

And extend does not work as expected:

WARNING on line 42 of ....../_modals.css.scss: ".row" failed to @extend ".row". The selector ".row" was not found. This will be an error in future releases of Sass. Use "@extend .row !optional" if the extend should be able to fail.

How should I do it properly?

Upvotes: 7

Views: 3668

Answers (2)

Hichem ben chaabene
Hichem ben chaabene

Reputation: 145

The .row has to be in the same file somewhere in the previous lines of code.

@extend is not that good and you can't use it within media queries, if you overuse it you will end up introducing inconsistencies on the code.

define a mixin in another file and use @import instead

Upvotes: 0

knagode
knagode

Reputation: 6125

Problem was because I also imported files via sass require/require_tree command.

 *= require_tree ./autoinclude

If all files are imported via @import function, everything works!

@import "autoinclude/*";

Upvotes: 4

Related Questions