Sass 3.3 and older
Inside mixin, no. If you are open to continue, you can get pretty close:
$orange: lighten(orange, 10%); %button { border: 1px solid $orange; background: $orange; padding:0; height:27px; text-transform: uppercase; color:white; display:block; } a%button { padding-top:10px 10px 0 10px; } button.my_button { @extend %button; } a.my_button { @extend %button; }
Compiles:
button.my_button, a.my_button { border: 1px solid #ffb733; background: #ffb733; padding: 0; height: 27px; text-transform: uppercase; color: white; display: block; } a.my_button { padding-top: 10px 10px 0 10px; }
Sass 3.4 and later
Starting from 3.4, we can explore and control the selector.
$orange: lighten(orange, 10%); @mixin button { border: 1px solid $orange; background: $orange; padding:0; height:27px; text-transform: uppercase; color:white; display:block; @if is-superselector('a', &) { padding-top: 10px 10px 0 10px; } } button { @include button; } b a.foo { @include button; }
Output:
button { border: 1px solid #ffb733; background: #ffb733; padding: 0; height: 27px; text-transform: uppercase; color: white; display: block; } b a.foo { border: 1px solid #ffb733; background: #ffb733; padding: 0; height: 27px; text-transform: uppercase; color: white; display: block; padding-top: 10px 10px 0 10px; }
source share