Skip to content

Instantly share code, notes, and snippets.

@joe-bell
Last active December 4, 2017 17:22
Show Gist options
  • Save joe-bell/c5ef9f006ee2fd445467af30118c8795 to your computer and use it in GitHub Desktop.
Save joe-bell/c5ef9f006ee2fd445467af30118c8795 to your computer and use it in GitHub Desktop.
Conditional Modifiers
/**
* Conditional Modifiers
*
* For example, here's a basic component with a "spaced" modifier:
*
* <div class="foo foo--spaced">
* <p class="foo__child">
* Hello
* </p>
* <p class="foo__child">
* I'm Spaced
* </p>
* </div>
*
* +----------+---------------+
* |Hello |I'm spaced |
* +----------+---------------+
*
* When we apply an extra "reversed" modifer, we want to flip the spacing, but
* we obviously don't want to apply this to all of our "foo" components right?
*
* TL;DR: Only if it's spaced *and* reversed:
*
* +----------+---------------+
* | Hello| I'm spaced|
* +----------+---------------+
*/
.foo--spaced {
> .foo__child {
padding-left: 20px;
/* .foo--reverse.foo--spaced > .foo__child { … } */
@at-root .foo--reverse#{&} {
padding-left: 0;
padding-right: 20px;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment