Answer the question
In order to leave comments, you need to log in
@extend in SASS. When is it time to stop - 2?
How justified is it in SASS to build type constructs
%background-gold
background-color: gold
.btn--twitter, .link--nav, .label--feedback.. //еще сто элементов
{ background-color: white }
.btn--submit, .link--outer, .label--subscribe.. //еще сто элементов
{ background-color: black }
.btn--reset, .link--readmore, .label--textarea.. //еще сто элементов
{ background-color: gold }
Answer the question
In order to leave comments, you need to log in
I usually take out color codes (like $face: #face8d
) into variables. This is a handy extension for naming colors that don't have CSS names. Another plus is that $face can be used for both bg and color, and much more. Otherwise, you make yourself a hostage of your own code.
And you don’t need to write a hundred elements in one line - the compiler will take care of this.
Good CSS is that you don't need to scroll a lot to make a couple of changes =)
I join those who answered above, and I will add that extend is not a tool that should be used everywhere. In the resulting code, extend will group all selectors in which another selector was called and append them. For example,
.selector-1, .selector 2 .selector-3, .selector-4 {
display:block;
}
All this is certainly good, but you just need to take into account a few points. Firstly, when using extend, our rules when translating to css will be written to the selector that we are extending, and not to the place where we write it in the scss file, which can cause some problems. For example, we want to redefine the color of an element, and if we do this through extend, then there is a chance that nothing will work, since the extend rules are usually located at the beginning of the code, and the rest of the rules follow further, and if we have a selector somewhere that sets the color to our element, then the rules from extend are applied first, and then again the color value that is defined further in the code. Here it is necessary to design well, so as not to accidentally get confused in these rules and so that one does not override the other.
Secondly, you need to remember that extend does not work inside media queries, since there is a different scope there, so you will either have to duplicate everything with mixins, or just write normal css code inside media queries.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question