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 trialVijayalaxmi vastrad
2,789 Pointshow 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
melissamyra
Front End Web Development Techdegree Graduate 18,858 PointsTo 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
1,704 PointsIf 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
2,789 PointsOHH THANK YOU SO MUCH, I AM BEGINNER TO SCSS, JUST STARTED LEARNING BASICS I DO NOT NO MIXINS CONCEPT.