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 trialAlex Rodriguez
Front End Web Development Techdegree Student 20,810 PointsWhat is this code doing in the begging on the main.css?
I open up the project files on the top of the main.css this code shows up
*, *:before, *:after { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
What is this doing? I m having a hard time understanding.
Thank you
3 Answers
Ryan Field
Courses Plus Student 21,242 PointsHi, Alex. That bit of code is making it so that elements on the site will include the border and padding inside the total size of elements. Normally, if you have a 200px by 200px div, for example, any padding and borders will be calculated in addition to that, meaning your final element will be larger than 200px by 200px. With box-sizing: border-box;
, however, this ensures that any padding and borders will be included inside the total, so your elements are always the size you specify them to be. The asterisk (*) is a universal selector, and will select all elements anywhere on the page.
Alex Rodriguez
Front End Web Development Techdegree Student 20,810 PointsThat make sense, thank you.
Ryan Field
Courses Plus Student 21,242 PointsYou're very welcome! :)
Daniel Vazquez
Courses Plus Student 7,905 Points."*"... means all elements, ":before" and ":after " are pseudo-elements
That code only sets the default box sizing for elements and pseudo-elements on the page