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 Adding Pages to a Website Add Iconography

Philip Condon
Philip Condon
8,605 Points

Why are we using px instead of % for min-height/max-height, padding, etc?

I'm not sure if my question makes sense but aren't px a fixed number. Wouldn't it make more sense to make all these values "relative" by using %?

1 Answer

Michael DeWitt
Michael DeWitt
2,166 Points

Short answer: You can use either. px for "fixed", % for fluidity.

Long(er) answer: each has specific use cases and it is important to know when to use one over the other. I think px is an easier concept to teach to a beginner, which is why I'm sure Treehouse chose to start with this. There are too many specific/advanced cases where one might be preferable to the other, which I'm sure will become apparent with more experience.

Philip Condon
Philip Condon
8,605 Points

Does treehouse eventually show examples of these cases? Could you explain some?

Michael DeWitt
Michael DeWitt
2,166 Points

I'm not sure how deeply Treehouse goes into this, I have not done the full CSS course. However, here is a cool example of % padding and margins to make responsive image sprites.

http://blog.brianjohnsondesign.com/responsive-background-image-sprites-css-tutorial/

However, what if you just wanted to add some padding to make a button for a link? It might be more appropriate there to add some pixels of padding and avoid interacting with the size of the container...

Hello css spanish colombia lenguaje i programming in development help!