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 trialAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Pointsmargin and padding
I have always seen writing this code in the beggining of the css document. Is it necessary to write? What does it actually do?
*,html{
margin: 0;
padding: 0;
}
2 Answers
Jake Milburn
13,608 PointsThis selector generally targets the entire document and sets all of the margins and padding to 0 before you've got started, essentially giving you a level playing field to work from. In earlier videos you have maybe seen the teachers using something called normalize.css. This is essentially the same concept except it is only resetting margins and padding as oppose to a whole array of properties.
Xayaseth Boudsady
21,951 Points*, html {
margin: 0;
padding: 0;
}
The star or asterisk (*) generally means you're selecting "all". Basically what you are doing is selecting all the elements on the document and setting the margin to 0, and padding to 0.
The CSS used above will strip off the margins and padding from the <html> element, if any apply. (Some browsers will automatically add margins or padding to the <html> element, so this CSS will override the default browser styling)
Since each browser is different, there are different default setting for each browser.