ElFik
ElFik

Reputation: 1027

How can I use css wildcard selectors and use the wildcard value as an attribute with scss

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?

Upvotes: 2

Views: 2401

Answers (1)

Sean Stopnik
Sean Stopnik

Reputation: 1868

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
}

Upvotes: 1

Related Questions