Skip to content

Instantly share code, notes, and snippets.

@CodeRecipez
Last active December 15, 2015 12:29
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 CodeRecipez/5260723 to your computer and use it in GitHub Desktop.
Save CodeRecipez/5260723 to your computer and use it in GitHub Desktop.
Sass 101 - A newb's guide: Selector bubble up

@media directives in Sass behave just like they do in plain CSS, with one extra capability: they can be nested in CSS rules.

If a @media directive appears within a CSS rule, it will be bubbled up to the top level of the stylesheet, putting all the selectors on the way inside the rule. This makes it easy to add media-specific styles without having to repeat selectors or break the flow of the stylesheet.

SCSS

.box {
  width: 800px;
  @media only screen and (max-width: 320px) {
    width: 97%;
  }
}

Sass

.box
  width: 800px
  @media only screen and (max-width: 320px)
    width: 97%

SassMeister Gist

.box {
width: 800px;
@media only screen and (max-width: 320px) {
width: 97%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment