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 CSS Layout Techniques Display Modes Block vs. Inline Elements

Gareth Powell
PLUS
Gareth Powell
Courses Plus Student 7,016 Points

Can we use two of the same selectors separately?

Hi. I noticed Guil used (I think) the ".main nav" two or three times. For example:

.main nav { padding: 0; }

.main nav { margin: 10px; }

My question is, can we use the same selector numerous times or should they be used as one declaration, e.g.:

.main nav { padding: 0; margin: 10px; }

?

Thanks

2 Answers

Stone Preston
Stone Preston
42,016 Points

if they truly are selecting the same thing then yes put them together

However it looks like guils selectors are not the same. looking at the video he has

.main-nav a {} /* selects links that are children of main-nav class */
.main-nav li {} /* selects list items that are children of main-nav class */

which dont select the same elements. so putting them together would not yield the intended result

Gareth Powell
Gareth Powell
Courses Plus Student 7,016 Points

Wow! That was quick! Thanks Stone, you have helped clarify this for me.

Cheers!