Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using units of measure in CSS

From: XHTML and HTML Essential Training

Video: Using units of measure in CSS

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.

Using units of measure in CSS

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.

Show transcript

This video is part of

Image for XHTML and HTML Essential Training
XHTML and HTML Essential Training

59 video lessons · 80658 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 10s
    1. Welcome
      1m 16s
    2. Using the exercise files
      1m 23s
    3. Choosing a text editor
      2m 31s
  2. 15m 46s
    1. Introducing HTML and XHTML
      2m 53s
    2. Understanding versions of HTML and XHTML
      2m 25s
    3. Exploring a simple XHTML page
      4m 47s
    4. Understanding the structure of an XHTML document
      2m 58s
    5. Understanding document containers
      54s
    6. Creating and using templates
      1m 49s
  3. 42m 4s
    1. Understanding how empty space is formatted in XHTML
      2m 42s
    2. Using paragraph tags
      2m 42s
    3. Aligning paragraphs
      2m 49s
    4. Understanding block-level and inline tags
      1m 24s
    5. Controlling line breaks and spaces
      5m 43s
    6. Formatting text with phrase element tags
      3m 28s
    7. Formatting text with font markup elements
      3m 24s
    8. Adding document structure with headings
      3m 25s
    9. Formatting quotations and quote marks
      2m 19s
    10. Preserving pre-formatted text
      1m 30s
    11. Selecting a typeface
      4m 33s
    12. Selecting a type size
      2m 11s
    13. Using ordered and unordered lists
      5m 54s
  4. 7m 48s
    1. Using inline images
      3m 17s
    2. Flowing text around an image
      2m 4s
    3. Breaking lines around an image
      2m 27s
  5. 22m 34s
    1. Working with hyperlinks
      7m 46s
    2. Using relative URLs
      3m 5s
    3. Specifying a base URL
      2m 4s
    4. Linking within a page using fragments
      4m 28s
    5. Creating image links
      5m 11s
  6. 22m 56s
    1. Introducing tables
      4m 37s
    2. Formatting tables with CSS
      8m 50s
    3. Aligning images with tables
      5m 7s
    4. Reviewing an alternative solution using CSS
      4m 22s
  7. 14m 31s
    1. Introducing frames
      7m 56s
    2. Hiding frame borders
      3m 15s
    3. Creating inline frames using iFrame
      3m 20s
  8. 20m 50s
    1. Introducing forms: part 1
      10m 37s
    2. Introducing forms: part 2
      7m 45s
    3. Using CGI with forms
      2m 28s
  9. 25m 42s
    1. Introducing CSS
      3m 11s
    2. Understanding levels of inheritance
      6m 10s
    3. Learning CSS syntax
      11m 23s
    4. Using units of measure in CSS
      4m 58s
  10. 1h 45m
    1. Comparing table layout and CSS layout
      1m 25s
    2. Exploring the finished web site
      2m 37s
    3. Building a document header
      8m 18s
    4. Placing a banner and a contact button
      8m 13s
    5. Laying out a main menu
      6m 55s
    6. Creating a layout template: main body area
      13m 31s
    7. Creating a layout template: sidebar area
      5m 17s
    8. Creating a layout template: footer content
      4m 46s
    9. Building a main home page: main body content
      11m 24s
    10. Building a main home page: sidebar content
      8m 52s
    11. Creating a page with a menu, graphics, and formatted links
      13m 26s
    12. Creating a page containing an ordered list
      6m 44s
    13. Creating a page containing video
      10m 45s
    14. Touring the finished site
      3m 45s
  11. 53s
    1. Goodbye
      53s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed XHTML and HTML Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.