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 How to Make a Website Customizing Colors and Fonts Resize Text

Ginny Garza
Ginny Garza
21,395 Points

Why should we repeat a selector ("body") on the CSS for different properties?

In the video Resize Text for Building a Website track, even though we already had a

body { background-color: #fff; color: #999; }

we open another selector on another part of the CSS stating

body { font-family: 'Open Sans', sans-serif; }

Is this a style choice of whoever is building the website, or is there a benefit to this kind of markup instead of

body { background-color: #fff; color: #999; font-family: 'Open Sans', sans-serif; }

Thanks!

2 Answers

Kevin Korte
Kevin Korte
28,148 Points

It is by choice, and as you start working on larger projects, it my make sense to have your CSS organized so all the font-styles are in one group, color styles in another etc, which may mean you have to duplicate selectors at the expensive of not having to scan through a 5000 line CSS document with no order when you want to change your font family.

At the end of the day, it's about what makes sense for you.

Bryan Manhollan
PLUS
Bryan Manhollan
Courses Plus Student 7,863 Points

You are correct. Although if I remember correctly, they separate those options for different purposes later in the course. By the end, everything will look very clean and have a purpose.