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

Is it okay to combine the "nav," "nav a," and "nav a:visited" rules?

In the video we're shown two separate rules, like this:

nav {
  background: #599a68;
}

nav a, nav a:visited {
  color: #fff;
}

I tried combining the two rules, and it seemed to work the same way.

nav, nav a, nav a:visited {
  background: #599a68;
  color: #fff;
}

Is it alright to combine both rules this way, or do I need to keep them separate for some reason?

Thanks!

2 Answers

You should only combine rules if you want elements to look the same ( Like you want to have paragraph in the header and the one in the section same size and set combined rule to 15px but then you decided it's to small so you change it to 20px ). Do not just combine them because there happened to be same rule in both. Hope you find that helpful.

Agreed. It's also possible to format like so for readability:

nav, 
nav a, 
nav a:visited {
  background: #599a68;
  color: #fff;
}

Just don't forget the commas between ids/elements/classes! Use to make that mistake all the time :] Good luck!

Thanks so much to both of you! Cheers!