Sass extend class from module

和自甴很熟 提交于 2021-01-29 14:06:08

问题


With the new module system in sass (with @use instead of @import) how can i define a class in one file and the use it in another file with @extend ?

File colors.scss

 .element {
   background-color: blue;
 }

main file

@use "./colors.scss" as colors;
body {
  @extend .element;
}

This gives the following error:

"body" failed to @extend ".element". The selector ".element" was not found. Use "@extend .element !optional" if the extend should be able to fail.

Example: https://stackblitz.com/edit/angular-tufq7f?file=src%2Fstyles.scss

How can I tell sass to get it from colors.scss?


回答1:


Turns out there are a few different problems here. The first is that the stacblitz example is using an old version of sass witch does not have module support. The other is that there is no way to specify from witch sass module to extend a css class from. The correct solution is what I wrote in the question:

@extend .element;



来源:https://stackoverflow.com/questions/59630514/sass-extend-class-from-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!