Answer the question
In order to leave comments, you need to log in
What order should I write Sass selectors in?
Now I write selectors in this order:
.block-class {
@include some-mixin();
some-rule: value;
another-rule: value;
&:hover {
// ...
}
@media ... {
// ...
}
&_modifier {
// ...
}
&__element {
// ...
}
&__another-element {
// ...
}
}
.block:hover
(or .block_modifier
) you need to change the nested .block__element
, then it turns out that this rule is set before the .block__element
. Stylelint swears at "no-descending-specificity" with standard settings, and you can get confused. :hover
to &_modifier
the end, then "no-descending-specificity" will be fixed, but it becomes stupidly inconvenient - you need to scroll through the entire file to understand if the element has any states at all. Answer the question
In order to leave comments, you need to log in
.block {
$this: &;
color: red;
&__element { font-size: 12px; }
&:hover &__element { transform: scale(1.1); }
@media () {}
//==
//== Модификация какая-то
//== ==========================
#{$this}_mod {
color: green;
&__element { font-size: 16px; }
@media () {}
}
#{$this}__mod:hover &__element { transform: scale(1.1); }
//==
//== Другая модификация
//== ==========================
&_mod { background: yellow; }
@media () {}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question