Is it possible in SASS to inherit from a class in

2019-01-31 05:08发布

The question pretty much says it all.

For instance, if I were using, say, Twitter Bootstrap, could I define classes in my own SASS stylesheet that inherit from Bootstrap's CSS classes? Or does inheritance in SASS only work within the scope of a single file?

3条回答
老娘就宠你
2楼-- · 2019-01-31 05:26

To my knowledge, you have to use @import of the file containing the classes you want to use into your SASS file in order to utilize them in that file. However, I am not a SASS/SCSS expert, so someone may know of another way to remotely use them that I am not aware of.

查看更多
3楼-- · 2019-01-31 05:37

**I might be mistaken, but if I get what you're trying to do, can't you just use the @extend .classname; command inside the element that you'd want to extend? Naturally, you should only modify your own code to preserve updatability.

查看更多
虎瘦雄心在
4楼-- · 2019-01-31 05:41

YES! its possible.

If you want all <button> elements to inherit the .btn class from Twitter Bootstrap's Default buttons

In your styles.scss file you would have to first import _bootstrap.scss:

@import "_bootstrap.scss";

Then below the import:

button { @extend .btn; }
查看更多
登录 后发表回答