Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In sass can I have &x&y&z

Tags:

css

sass

In sass I want to do

asdf{
   &-b&-c {font-size: 16px;}
}

For the css generated to be

asdf.asdf-b.asdf-c{
   font-size: 16px;
}

Is this possible to do in sass? Or am I going to have to write out to parent element multiple times

like image 867
wjwtheone Avatar asked Feb 01 '26 04:02

wjwtheone


2 Answers

You can use mixins:

@mixin fontSize($selector) {
  .#{$selector}.#{$selector}-b.#{$selector}-c {
    font-size: 16px;
  }
}

@include fontSize("asdf");

Result

.asdf.asdf-b.asdf-c {
  font-size: 16px;
}
like image 56
Engineer Avatar answered Feb 02 '26 22:02

Engineer


If you were using Less the syntax would be:

.asdf {
  &&-b&c {
    font-size: 16px;
  }
}

However, Sass doesn't allow for & to be directly joined with another & in the same selector. Instead, reuse must make use of interpolation (#{...}):

.test {
  &#{&}-b#{&}-c {
    font-size: 16px;
  }
}
like image 32
zzzzBov Avatar answered Feb 02 '26 22:02

zzzzBov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!