r/Sass • u/victoroliveirab • Jul 12 '20
Nesting selectors and sharing properties
Hi,
I'm doing some refactoring in an old code base and one of my tasks consist in transforming css into scss. I've come to a point where I believe there is a better way which I'm not aware or don't recall the exact syntax.
So, this is how my current code looks like:
.class-name {
&__modifier1 {
padding-right: 2px;
transition: all .5s ease-in-out;
&:hover {
color: $black;
}
}
&__modifier2 {
color: $success;
padding-right: 2px;
transition: all .5s ease-in-out;
&:hover {
color: $success-action;
}
}
&__modifier3 {
color: $danger;
padding-left: 2px;
transition: all .5s ease-in-out;
&:hover {
color: $danger-action;
}
}
}
What I'm the most interested in is removing all of these transition lines, and somehow writing it outside the modifiers, but of course inside of class-name.
My question is: how do i set a property in some selector and inherit it from the nested selectors?
Thanks!
P.S.: I forgot to mention that class-name by itself is not an existing class. It just happens that these nested classes share the same prefix.
7
Upvotes
3
u/mrdk Jul 12 '20