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
kj2
5,933 Points%, em, px
If i want to make an element wider or taller, example a div thats a rectangle, what would be the best CSS practice to make it wider and taller?
having trouble with %, em, and px, when to use each one
2 Answers
Adam Moore
21,956 PointsWell, em, I'm pretty sure, are mainly just used for font sizes; or at least that's all that I've seen them used for. As for % and px, it depends on what the element will need to do. If you are wanting it to remain a certain size, then use px. If you are wanting it to move with the browser (such as setting a width to 100% for a header that will always need to stretch the width of the browser window), then you might want to use %.
If you are going for a responsive design, accounting for many different screen sizes, you may have to use media queries, alternating between % and px for the best look of each element on the page.
kj2
5,933 PointsThank you Adam!