Is there any way to “unextend” a class in SASS?

2019-01-27 20:41发布

问题:

Right now I have a class that I'm @extend-ing to all button elements. However, I would like to not extend it to one single button and would prefer not to resort to changing the HTML to make it a link.

Is there any way to remove the @extend for a particular rule in SASS?

回答1:

No. Your options are:

  1. Don't style all buttons (use classes or more specific selectors to avoid your unique element)
  2. Override the styles of the unique element (depending on the styles used, it can be very difficult to return a button to its default appearance for every browser)

The least painful solution for you would be to use the :not selector:

// style all buttons, except for ones with the "default" class on them
button:not(.default) { %extend theStyles }