Asim K T Asim K T - 6 months ago 26
CSS Question

More precedence/specificity to CSS class in LESS

I've a LESS code like:

.block__element {
background: red;
&--modifier {
background: yellow;
}
}


I want more specificity to .block__element--modifier such as:

.block__element.block__element--modifier {
background: yellow:
}


So that it can overrides some other styles.
I can achieve it by:

.block__element {
background: red;
&--modifier.block__element {
background: yellow;
}
}


I want to know is there any easy way?

Answer
.block__element {
    background: red;
    &&--modifier {
        background: yellow;
    }
}

link

Comments