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 CSS Foundations Advanced Selectors Pseudo-Elements: ::before and ::after

Lou Chua
Lou Chua
8,338 Points

When using pseudo-elements, to which element are rules being applied?

As the title says, when using ::before or ::after like in the video are the additional rules like margin and padding going to be applied to the content being inserted or will it be applied to the element specified by the selector?

(ex. when the .pdf image in inserted before the dload class are the margins being applied to the class or the inserted image?)

1 Answer

Scott Moore
Scott Moore
4,050 Points

Lou, they are going to be applied to class. Lets say you put the image in ::whichever. Then apply padding. It will move the image away from whater it is it is next to. Try it in a codepen to see. Hope it helps.

Lou Chua
Lou Chua
8,338 Points

I think I got it now. Thanks!