How can I use css wildcard selectors and use the w

2019-08-09 05:02发布

问题:

I have a set up where I'd like to select elements based on partial class in scss.

I know of the wildcard selector which I could use div[class*='-suffix'] however within the class definition, I'd like to use that wildcard value. For example:

.{prefix}-glyph
{
   @include mymixin({prefix})
}

Where {prefix} is the wildcard prefix I wish to match against.

Is this possible?

回答1:

What you are trying to do, though don't see why you would want to do this? Its requires more typing:

Mixin

@mixin myMixin($name) {

  .#{$name}-name {
      @content;
  }
}

Usage

@include myMixin(class) {
    // YOUR STYLES
};

Output

.class-name {
    // YOUR STYLES
}