:after and :before pseudo-element selectors in Sass

CssCss SelectorsSassPseudo Element

Css Problem Overview


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.

Css Solutions


Solution 1 - Css

Use ampersand to specify the parent selector.

SCSS syntax:

p {
    margin: 2em auto;

    > a {
        color: red;
    }

    &:before {
        content: "";
    }

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarco GodínezView Question on Stackoverflow
Solution 1 - CssshellbroView Answer on Stackoverflow