How to override style in imported scss file

女生的网名这么多〃 提交于 2020-01-25 06:52:15

问题


My Jekyll blog's theme has a scss file with the following syntax related style in minima.scss:

.highlight {
  background: #fff;
  @extend %vertical-rhythm;

  .highlighter-rouge & {
    background: #eef;
  }

  .err   { color: #a61717; background-color: #e3d2d2 } // Error

// more stuff

I want to override the nested .highlight -> .err style only, but I don't want to set the color and bg-color attributes to anything specific, just the default. As in, I want it as if the .err style had never been defined in the first place.

I consume the minima.scss file in a main.scss which (which is the the actual file included in the page), like so:

@import "minima";

.highlight {
    .err { ???? }
}

This makes it easy to add styles, easy to extend styles with new attributes, and easy to override specific attributes of styles (since I guess the second mention takes priority), but how do I "delete" style or elements?


回答1:


@import "minima";

.highlight {
  .err {
    color: unset !important;
    background-color: unset !important;
  }
}

Should do the trick. You can read more about "unset" and "!important".




回答2:


setting the color to inherit will make it take it's parent element color which in this case looks to be white




回答3:


The answer that's marked correct is not the recommended way at all. In fact, it's a terrible way to override a style.

The correct way to do this:

@import "minima";

.highlight {
  &.err {
    color: unset;
    background-color: unset;
  }
}

HTML:

<div class="highlight err"></div>


来源:https://stackoverflow.com/questions/59013314/how-to-override-style-in-imported-scss-file

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