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

It is useful to use a nested rule’s parent selector in other ways than the default. For instance, you might want to have special styles for when that selector is hovered over. In these cases, you can explicitly specify where the parent selector should be inserted using the & character.

This technique will work for any pseudo class such as :after, :before, :active, and so on.

SCSS

a {
  color: red;
  text-decoration: none;
  &:hover {
    text-decoration: underline;
  }
}

Sass

a
  color: red
  text-decoration: none
  &:hover
    text-decoration: underline

SassMeister Gist

a {
color: red;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment