简体   繁体   English

Sass/Scss 为插件重用相同的 styles

[英]Sass/Scss reuse same styles for addon

So I have a class that I have applied some styles too as shown below:所以我有一个 class 我也应用了一些 styles 如下所示:

.onetrust_container {
  display: grid;
  place-items: center;
  height: 50vh;
  text-align: center;

  &-map {
    height: 100vh;
  }
}

For some odd reason, the -map addon doesn't reuse the above styles, such as this:由于某些奇怪的原因, -map插件没有重用上面的 styles,例如:

在此处输入图像描述

I want to have the following items:我想要以下物品:

.onetrust_container {
  display: grid;
  place-items: center;
  height: 50vh;
  text-align: center;
}
.onetrust_container-map {
  display: grid;
  place-items: center;
  height: 100vh;
  text-align: center;
}

All help will be appreciated!所有帮助将不胜感激!

The way you wrote the first code block, the onetrust_container-map class does not inherit the CSS directly above it.您编写第一个代码块的方式, onetrust_container-map class 不会直接继承它上面的 CSS。 Nesting selectors with the & operator allows you to reuse the parent selector, but that specific operator does not mean that the child selector inherits its parent's CSS unless you explicitly say so.使用&运算符嵌套选择器允许您重用父选择器,但该特定运算符并不意味着子选择器继承其父选择器的 CSS,除非您明确说明。

Your compiled CSS: https://www.sassmeister.com/gist/cbb69d8c522827b553787559671c405a?token=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&scope=gist,read:user Your compiled CSS: https://www.sassmeister.com/gist/cbb69d8c522827b553787559671c405a?token=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&scope=gist,read:user

If you want the &-map to inherit its parent's CSS while applying its own, you'll want to structure the SASS that way:如果您希望&-map在应用它自己的同时继承其父级的 CSS,您需要以这种方式构造 SASS:

.onetrust_container {
  &, &-map {
    display: grid;
    place-items: center;
    height: 50vh;
    text-align: center;
  }

  &-map {
    height: 100vh;
  }
}

https://www.sassmeister.com/gist/85801d79d309cc5d10ac22ad2839af35?token=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&scope=gist,read:user https://www.sassmeister.com/gist/85801d79d309cc5d10ac22ad2839af35?token=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&scope=gist,read:user

For the &, &-map selector, you're saying "The parent selector, and 'The parent selector'-map"对于&, &-map选择器,您说的是“父选择器和'父选择器'-map”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM