Reputation: 14773
I would like to know how I can avoid writing certain styles twice if they are the same for an element and it's possible pseudo classes:
.element {
color: #a0c225;
&:hover {
color: #a0c225;
}
&:focus {
color: #a0c225;
}
}
and I don't want to repeat the color #a0c225
in SASS?
Upvotes: 0
Views: 72
Reputation: 829
I would use something like this:
$col-example: #a0c225;
%class-example {
color: $col-example
}
.element {
@extend %class-example;
/* more properties */
&:hover {
@extend %class-example;
/* more properties */
}
&:focus {
@extend %class-example;
/* more properties */
}
}
which will compile to:
.element, .element:hover, .element:focus {
color: #a0c225;
}
.element {
/* more properties */
&:hover {
/* more properties */
}
&:focus {
/* more properties */
}
}
Upvotes: 0
Reputation: 1508
You could use &
to do something like this:
.element {
&, &:hover, &:focus {
color: #a0c225;
}
}
Which would compile to:
.element, .element:hover, .element:focus {
color: #a0c225;
}
Upvotes: 1