Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Foundations Advanced Selectors Pseudo-Elements: ::before and ::after

Joseph Longo
Joseph Longo
1,074 Points

Help: the everything element!?!?

I asked this question in a previous post, but I think if I ask this question here, I will be able to receive more clarity on this topic.

*, *:before, *:after { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }

What does the above CSS mean/do, and when should I use it? I copied this code from the HTML forms wed design track. Basically, what does it do? Should I automatically just include this code in my CSS as good practice, EVEN IF I DO NOT understand it?



1 Answer

The * is known as the universal selector. Basically, it selects every element in your page. In this case, that box-sizing property is being applied to every element, as well as any :before or :after psuedo-elements, on the page.

This technique of setting the box-sizing property on every element to border-box is popular because it tells every element to include padding and borders in their defined width instead adding them to the width. This makes calculations a lot easier to handle since you can add padding and borders to an element without the width suddenly changing on you.

For further reading and even a more modern update on this technique, check out this great blog post by Paul Irish.