Answer the question
In order to leave comments, you need to log in
How to use BEM mixins (**modifiers** — I wrote something wrong) BEM?
If you assign a modifier to a block, then a cascade is obtained to modify the element. If you assign a modifier to each element, you get a bunch of additional classes, which can probably be called redundancy. How right?
HTML:
<div class="button button_red" lang="html">
<i class="button__i"/>
<span class="button__txt">Lorem</span>
</div>
.button{
......
}
.button__i{
......
}
.button__txt{
......
}
/* как видно ниже модификатор блока порождает каскад */
.button_red .button__i{
color: red;
}
.button_red .button__txt{
color: red;
}
Answer the question
In order to leave comments, you need to log in
SCSS mixin
/// Block Element
/// @access public
/// @param {String} $element - Element's name
@mixin element($element) {
&__#{$element} {
@content;
}
}
/// Block Modifier
/// @access public
/// @param {String} $modifier - Modifier's name
@mixin modifier($modifier) {
&--#{$modifier} {
@content;
}
}
.block {
/* CSS declarations for `.block` */
@include element('element') {
/* CSS declarations for `.block__element` */
}
@include modifier('modifier') {
/* CSS declarations for `.block--modifier` */
@include element('element') {
/* CSS declarations for `.block--modifier__element` */
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question