Skip to content

Instantly share code, notes, and snippets.

@guoyunhe
Last active May 7, 2019 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guoyunhe/038e979d692cea120b79986ae466584e to your computer and use it in GitHub Desktop.
Save guoyunhe/038e979d692cea120b79986ae466584e to your computer and use it in GitHub Desktop.
BEM, SaSS, Nesting...
// Good: don't break inside blocks, elements or modifiers
.my-button {
&__icon-left {
//
}
&__icon-right {
//
}
}
// Bad: break inside blocks, elements or modifiers
.my-button {
&__icon {
&-left {
//
}
&-right {
//
}
}
}
// Good: avoid chained elements and modifiers
// In this way, we can keep a nice clean two level nesting structure
.my-panel {
&__inner {
//
}
&__header {
//
}
&__title {
//
}
&__cover {
//
}
&__content {
//
}
&__footer {
//
}
&__button {
//
}
}
// Bad: use chained elements or modifiers
// This style makes too many nesting levels
.my-panel {
&__inner {
&__header {
&__title {
//
}
&__cover {
//
}
&__button {
//
}
}
&__content {
//
}
&__footer {
&__button {
//
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment