Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.