What is the equivalent of LESS's “import (reference) 'style'” in SASS

爷,独闯天下 提交于 2019-12-06 16:47:53

问题


In addition to application.css.scss, I have multiple partials like homepage.css.scss. At the moment I have to add @import 'bootstrap' to each one of them in order to use bootstrap variables and mixins.

Let's say I want to change my default links colour to red, I'd add that to application.css.scss. But the links in homepage.css.scss will not be red because the bootstrap import will override it with blue.

In LESS, I can do @import (reference) "bootstrap", how can I do that in SASS?


回答1:


The closest you will get is a silent class / placeholder. These work a little different to how LESS and reference work, you can read more on them here: http://blog.teamtreehouse.com/extending-placeholder-selectors-with-sass

LESS

lib.less

.class {
   background: red;
}

main.less

@import (reference) "lib";

.anotherClass {
   &:extend(.class);
}

SASS

lib.sass

%class {
  background: red;
}

main.sass

@import "lib";

.anotherClass {
  @extend %class;
}

CSS Output

.anotherClass {
  background: red;
}


来源:https://stackoverflow.com/questions/22851662/what-is-the-equivalent-of-lesss-import-reference-style-in-sass

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