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 trialBenjamin Hedgepeth
5,672 PointsApplying background-color to :root vs body
What factors would lead to applying a background color to the body element and not the :root and vice-versa?
1 Answer
Steven Parker
231,269 PointsIf the body had styles applied that caused it to not cover the entire viewport (such as an explicit width or margins), you might want to apply a background to its parent element instead. And for the same reason, you might want to use the body to limit it only to the body area.
Note that for an HTML document, the html selector will target the same thing as :root, though :root has a higher specificity (class vs. tag).
Kailash Seshadri
3,087 PointsKailash Seshadri
3,087 PointsSo in a HTML document,
and
will do the same thing to the webpage.