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) The Box Model Display Values

Colin K
Colin K
3,417 Points

% or px for padding?

Guil has used px and % at different times for padding. Surely it is best practice to always use % as this will be more responsive? Can someone explain why he uses px?

Niall Maher
Niall Maher
16,985 Points

I usually use px for top and bottom and % for left and right. Meaning the width is adjustable and the height will be a fixed height. Common for responsive web design. Again knowledge is power so it just offers you more control over your design

2 Answers

The percentage values are becoming more commonly used as responsive web design is growing in popularity. However, px values give precise control over the element. It is common in responsive web design to use % for left, right and fixed px for top and bottom. Using a fixed px value will ensure the padding between elements remains consistent even with the changing screen sizes.

Colin K
Colin K
3,417 Points

Thanks for your answers! That has helped. :)