:after and :before pseudo-element selectors in Sass

Marco Godínez picture Marco Godínez · May 25, 2012 · Viewed 276.7k times · Source

How can I use the :before and :after pseudo-element selectors following the syntax of Sass or, alternatively, SCSS? Like this:

p
  margin: 2em auto
  > a
    color: red
  :before
    content: ""
  :after
    content: "* * *"

Of course, the above fails.

Answer

shellbro picture shellbro · May 25, 2012

Use ampersand to specify the parent selector.

SCSS syntax:

p {
    margin: 2em auto;

    > a {
        color: red;
    }

    &:before {
        content: "";
    }

    &:after {
        content: "* * *";
    }
}