Should nesting same name blocks be allowed? #259
Replies: 4 comments
-
I think you are right, it causes unexpected and not desired complexity |
Beta Was this translation helpful? Give feedback.
-
I think when you expect nesting like this you have to be more specific, using the .foo {
&__text {
.foo--red > & {
color: red;
}
.foo--blue > & {
color: blue;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
That can be a potential solution, but it enforces too much on the DOM hierarchy. This also makes it harder to manage the code when there are changes to the DOM. I think this can work on simple cases. |
Beta Was this translation helpful? Give feedback.
-
When you're dealing with recursion, you really don't have a choice. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
So I was having a conversation with a colleague and I stated that we should not be nesting a BEM block within itself because it can cause CSS selector nightmare. Below I will show a simple example:
This is a very small and hopefully clear example. What color would
.foo__text
get? I can't find any guide that suggests or argues with nesting same named blocks.Beta Was this translation helpful? Give feedback.
All reactions