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/5260709 to your computer and use it in GitHub Desktop.
Save CodeRecipez/5260709 to your computer and use it in GitHub Desktop.
Sass 101 - A newb's guide: parent selector reference (selector prefixing)

Sometimes it is necessary to prefix the rule you are engineering with another selector that appears higher up in the DOM. This becomes particularly useful when working with tools like Modernizer.

In this case, you can explicitly specify where the parent selector should be inserted by placing the selector before the & character.

SCSS

.box {
  box-sizing: border-box;
  width: 800px;
  padding: 30px;
  border: 1px solid black;
  .no-boxsizing & {
    width: 738px;
  }
}

Sass

.box
  box-sizing: border-box
  width: 800px
  padding: 30px
  border: 1px solid black
  .no-boxsizing &
    width: 738px

SassMeister Gist

.box {
box-sizing: border-box;
width: 800px;
padding: 30px;
border: 1px solid black;
.no-boxsizing & {
width: 738px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment