Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropping the parent modifier #4

Closed
maxhoffmann opened this issue Sep 2, 2014 · 4 comments
Closed

Dropping the parent modifier #4

maxhoffmann opened this issue Sep 2, 2014 · 4 comments

Comments

@maxhoffmann
Copy link
Owner

This is what the CSS the compiler would currently put out:

/* object */
.object { }

/* modifier */
.object--modifier { }

/* parent modifier */
._object--parentmodifier .object { }

Both override the .object styles: modifiers come after the object styles and parentmodifier have a higher specificity. The difference is their usage:

<div class="object object--modifier"></div>

<div class="_object--parentmodifier">
  <div class="object"></div>
</div>

So the question is if this difference in usage is helpful in some way. If not we could kill parent modifiers and alter modifiers so that they can be used in both ways.

/* object */
.object { }

/* modifier */
.object--modifier,
.object--modifier .object { }

Usage:

<div class="object object--modifier"></div>

<div class="object--modifier">
  <div class="object"></div>
</div>

Is there any advantage to have seperate modifiers? Any use case where this is more clear than just using one modifier?

@martzoukos
Copy link

Kill parent modifiers. BEM doesn't work like that.
:)

@martzoukos
Copy link

If you want to add a parent modifier, then the object object--modifier is sufficient. If you to override a child element, then this object--modifier object__element is also sufficient.

If you want to change some property of the parent (Block in BEM) in relation to its surrounding layout, then creating a new variation with a parrent modifier object--modifier is enough. If you feel that this variation is tightly tied with the parent container (and not repeatable anywhere else), then it might make sense to create a child style on the parent container parent-object object.
But this decision should be left to the developer, and it can also lead to leakage of styles between objects.

@maxhoffmann
Copy link
Owner Author

Yeah, I think we should go for simplicity.

Example Documentation:
“Use modifiers to alter objects. Add it to the object element or to one of its parent elements.”

@maxhoffmann
Copy link
Owner Author

There is an issue with pseudo selectors:

This:

=object

compiles to:

.object--modifier,
.object--modifier .object { }

That would also mean that this:

=object
  :hover
    outline: 1px solid red

compiles to:

.object--modifier:hover,
.object--modifier .object:hover {
  outline: 1px solid red;
}

This would add the outline to both elements if added to a parent element. Solution could be to scope the first modifier to its object:

.object.object--modifier:hover,
.object--modifier .object:hover {
  outline: 1px solid red;
}

Now the hover styles will only be active for modifiers that are on the object or for the object itself being nested under this modifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants