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

victor sagrista lopez
victor sagrista lopez
1,437 Points

Use cm on CSS?

Hi everybody, This is sort of a cultural question. As a European, I'm much more familiar with cm. Therefore, I write much better code on css using them instead of pixels. I's just so much easier for me. So my question is... Are pixels prefered at a professional level? If so, is there any reason for this? Thanks!

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Victor;

As a general rule use relative units for main body text that users are going to have to read a lot of (so they'll want to be able to read it comfortably); Absolute for text that has to be sized to match other elements on the page that are sized in pixels, such as images.

For relative, ‘%’ and ‘em’ are equally good.

For absolute, always use ‘px’.

If you look into some of the SASS courses here on Treehouse, they give a CSS function to convert pixels to em values so you don't have to do math calculations for every property:

@function em($target, $context: $base__font-size) {
    @return ($target / $context) * 1em;
}

I believe the principle is covered in a CSS course or two, and then the SASS courses show how to implement the funciton. Great stuff.

Just my thoughts,

Ken

Wayne Priestley
Wayne Priestley
19,579 Points

Hi Victor,

I don't think you'll ever see professional web designers use cm or inch. Pixels, em's, rem's (em's & rem's are a measurement based on pixels).

Computer screens use pixels for measurement, that fact alone is reason enough to use pixels in your code.
You will end up doing lots of math if you were attempting to code in cm.

Pixels aren't actually a European, American or Asian thing BTW, it's not like the metric measurement we use here versus the imperial measurement used elsewhere. Pixels are the standard for web designers throughout the world.

Hope this helps.

victor sagrista lopez
victor sagrista lopez
1,437 Points

Hi Wayne, Ken,

Thanks for your replies. Yeah, I figured pixels were the standard in CS & programming. I think that course is a great idea indeed. I live in the US now and have these issues too with feet, pounds, etc... lol I guess it's just getting used to it too,

Cheers,

Victor

James Barnett
James Barnett
39,199 Points

Getting a sense of how big 100px is kinda like getting a sense of how big an inch is, it comes with use.