rscss icon indicating copy to clipboard operation
rscss copied to clipboard

About nested components

Open lolenko opened this issue 9 years ago • 4 comments

Your structure does't work when we have nested components with same elements names.

.foo-1 {
  .bar {}
}

.foo-2 {
  .bar {}
}

.foo-1
  .bar
  .foo-2
    .bar

In this case selector .foo-1 .bar affects on "bar" element of "foo-2" component

In BEM it's fine

lolenko avatar Feb 09 '15 09:02 lolenko

.bar can be inside .foo-1 or .foo-2 and may have different properties. Is not the same element.

.foo-1
   .bar
.foo-2
   .bar

emmgfx avatar Feb 09 '15 11:02 emmgfx

Indeed that's true: https://github.com/rstacruz/rscss#bleeding-through-nested-components

You may need to use the child selector (> .bar) in those cases. (bonus: its more efficient than descendant selectors .foo-1 .bar!)

actually on that note, it might be a good idea to recommend > everywhere...

rstacruz avatar Feb 09 '15 13:02 rstacruz

In advance we don't know about nested case, so components are't independent.

We are limited by element nesting level in HTML, if we write > everywhere. Components can't always be quite simple.

lolenko avatar Feb 10 '15 09:02 lolenko

Avoid rule nesting at all costs, that's where BEM shines.

ValdasK avatar Feb 10 '15 09:02 ValdasK