Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Sass Basics Improve Your Workflow with Sass Use the Ampersand to Reference Parent Selectors

Vijayalaxmi vastrad
Vijayalaxmi vastrad
2,789 Points

how to apply both after and before pseudo elements to same element in scss

For example:

.circle:before { position: absolute; content: ""; /* more styles: width, height, etc */ }

.circle:after { position: absolute; content: ""; /* more styles: width, height, etc */ }

HOW TO WRITE THIS IN SCSS

3 Answers

To make this SCSS even more DRY, I would add

@mixin styles {
  position: absolute;
  content: "";
  width: 100px;
}

so

@mixin before-after-styles {
  &::before {
  @include styles;
  }
  &::after {
  @include styles;
  }
}
Sam Glister
Sam Glister
1,704 Points

If this was me writing this in scss and they both have exactly the same rules I would potentially use a mixin which should achieve what you are wanting to do.

@mixin before-after-stlyes {
 &::before {
 position: absolute;
 content: "";
 width: 100px;
}
&::after {
 position: absolute;
 content: "";
 width: 100px;
}
}

Then apply this to whichever elements with the include function.

.circle {
 @include before-after-stlyes;
}
Vijayalaxmi vastrad
Vijayalaxmi vastrad
2,789 Points

OHH THANK YOU SO MUCH, I AM BEGINNER TO SCSS, JUST STARTED LEARNING BASICS I DO NOT NO MIXINS CONCEPT.