Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this lesson we're going to talk about units of measurement in CSS. CSS uses units of measurement to say how big things are going to be, how far apart things are going to be. There are actually a lot of units of measurement available, and we're going to talk about just a few of the major ones. For a complete reference check with any CSS reference or with the CSS course here on Lynda.com. So here we have a document that's formatted with CSS and this is the Style Sheet that's being used for this document. We see that we have a few things in here that are measured already, especially in the P style, for the paragraph.
We have line-height, which is set to percent. So that's the percent of the size of the font in the paragraph. So it's set for 140%. If we change that to say 200%, you'll see that it changes down here in the document for all the paragraphs. We'll Save that and Reload, and now we have a larger separation between the lines, and you'll see that the bottom of this line is about twice the height of the line from the bottom of this line. Likewise, we have the text-indent, which is set in ems, two ems. Em refers to the width of the M in the font.
So here we have an M, right there. So this indent is supposed to be twice that width. It looks like it's a little bit more. One of the things that happen with typography-based measurements on a screen is that the screen itself is made up of pixels. So any typography-based measurement is going to have to be translated into pixels, and this would go also for inches and centimeters and things like that. It has to get translated into pixels. So it's going to depend on the dimensions of the pixels in your particular monitor. So it's always going to be a little bit off.
So that's just the fact of life in using raster-based media with something that's measured in absolute measurements like inches or ems or points or anything like that. So that's the em measurement. There's also an ex measurement, which refers to the height of a lowercase x. So I can say my line-height here is going to be say 3 exes, 3ex, like that. I'll Save. So that's to height-based measurement and it's based on the height of the lowercase letters in the document.
I Reload, and there we have, the space is set to one, two, three times the height of a lowercase x. So let's go ahead and set the size of the font in points. Fonts are typically measured in points, and we'll go ahead in here and we'll say font-size, and 12 points is the default typically, so I'm going to go ahead and make it 14 points. So I'll make it a little bit larger. pt stands for points. I'll save and I'll reload over here in the browser, and we see that the text is now larger.
All of the font-based measurements have been updated as well. Finally, let's talk about doing things in size of pixels. I just want to say that because a computer screen is a raster-based medium, when you're measuring things for a computer screen, pixels are what matters. Now, there's two ways to look at this. One is if you want a page to look exactly how you want it to look, measure things in pixels and it will come out pretty close. It's not always going to be exactly the same on everybody's monitor, and there is reasons for that, but it will be really, really close.
When you're measuring things that are fix number of pixels and size, things like the dimensions of an image, they will always be exact. But things like font-size tend not to be exactly the same from device to device when they're measured in pixels. There are reasons for that, and it has to do with how fonts are measured and how they're rendered. But the point is that if you care about how things are going to be relative to fixed pixel sized objects on the screen, you want to use pixels in your measurements. Now, the other side of this coin is that for people who like to change the size of the fonts on their computer screen, like older people who might have trouble seeing, they tend to increase the size of the fonts on their computer screen.
If you measure your fonts and your Style Sheet in exact pixels, they're not going to be able to do that anymore. So that's just another consideration to think about when you use the pixel measurements. Now that said, a lot of people like the pixel measurements because it allows them to exert a lot of control over how their page is rendered on the browsers that are viewing their page, and there's something to be said for that viewpoint. So we're going to look at that. I'm going to go ahead and I'm going to change this to 14 pixels instead of 14 points. You'll see how that looks different on the screen here.
I'm going to Save and go ahead and Reload, and there's the 14 pixels version rather than the 14 points version. Likewise, my indent here, I can measure that in pixels, I can go ahead and say 200 pixels for that and save that and Reload. We'll see that we get this nice big 200-pixel indent there for the first lines of our paragraphs. There you have it. Those are the units of measurement in CSS. Those are the most common ones. There are a few others available. For a complete reference you can check with any CSS reference or the CSS course here on Lynda.com.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99534 Viewers
56 Video lessons · 112757 Viewers
71 Video lessons · 81568 Viewers
131 Video lessons · 39158 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.