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 Basics (2014) Basic Layout Width and Height Properties

on minute 5:21 he uses 2 rules to define padding. Whats the benefit of that? Why not just set both values using 1 rule?

on minute 5:21 he uses 2 rules to define padding. Whats the benefit of that? Why not just set both values using 1 rule?

Is there ever any benefit to typing out two different rules when assigning values to different sides of an element? why couldnt he just use one padding rule and set both values there. i understand they'll both work the same but is there any benefit behind the extra typing besides making the code more understandable for beginners ?

thanks

2 Answers

The only other reason I could see is that you might have other rules applying padding to those elements, and only want to override particular ones. Otherwise the default/initial value is 0px for each side.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

No, I don't believe there to be any benefit over using the one rule with the shorthand. My instinct is to say that this was done this way for educational purposes. Given that this is a "CSS Basics" course, it's likely that padding-top: 10px; is easier to understand than the shorthand padding: 10px 0px 0px 0px; for those who are brand new to CSS and any sort of coding in general. :sparkles:

Thanks a lot! And That's what I thought. Just wanted to make sure I wasn't missing anything.