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

Altering line height

From: CSS Web Site Design

Video: Altering line height

What we're going to discuss in this chapter is, what is in fact, CSS Typography. Now, if you talk to someone who is really a hard-core typographer, they are going to get all excited about things like leading and kerning and serifs and swashes and probably buckles. For all I know there's a lot that goes into typography and you know, print designers in particular really, really get into it, and they get into fonts and tight catalogues and that sort of thing. CSS is not so advanced. It doesn't have what a typographer would think of as real kerning control or real leading control.

Altering line height

What we're going to discuss in this chapter is, what is in fact, CSS Typography. Now, if you talk to someone who is really a hard-core typographer, they are going to get all excited about things like leading and kerning and serifs and swashes and probably buckles. For all I know there's a lot that goes into typography and you know, print designers in particular really, really get into it, and they get into fonts and tight catalogues and that sort of thing. CSS is not so advanced. It doesn't have what a typographer would think of as real kerning control or real leading control.

In fact, those are terms that I only vaguely understand myself but I've talked to a lot of typographers and they tell me that CSS has basically almost nothing in the way of that. But what CSS does allow you to do is affect the fonts that are used, font sizes and some of the presentation of text and that's what we're going to be looking at in this chapter. So for this video what we're going to talk about is line-height, and how you can affect line-height on elements. So as a good basic example, when I say for paragraphs, we're going to have a line-height of three.

This is one of those rare cases in CSS where you can have a numeric value that doesn't have a unit after it. This doesn't mean three pixels and it doesn't mean 3 inches or 3 mm or 3 furlongs or 3 light years or any of those sort of things it's simply 3. What that basically does is it creates a multiplier, it multiplies the elements font size, by three and that gives the line-height. So for the font size here is 15 pixels. If that's what the font size were set to be, then the line-height for these paragraphs is going to be 45 pixels, that's 3 X 15.

The nice thing about the multiplier, of course, is that you don't have to know what the font size is going to be and even if it changes, the line-height stays proportional to whatever the font size is, which you can check out by using Cmd plus and minus to raise or lower the font size, assuming you're using Firefox or Mozilla or one of those kinds of browsers. So, what we've done here like it says, the line- height for paragraphs should be three times as font size.

There's another way to express it actually, which is let's say 3em, and that's going to have the same visual effect here, given the situation. No there is a difference between the two, which I'm going to discuss in just a minute. You can also, as you can tell, you're not only limited to multipliers, you can use light measures if you want to, although it's generally not a great idea. Here's an example, paragraph with the line- height of one pixel. Probably not what you wanted. Not what I would want certainly, but it's something that you can do.

You can't have negative line-heights, so don't get too many crazy ideas, but you can take them down as low as one pixel, just, you know, you probably shouldn't. You can just say line-height 1em and then you would get this sort of text, which is nice enough but if you're particularly attuned to the way that Web browsers sort of lay things up by default, this a little more crowded than is usually the case. This is not entirely the default, generally default is somewhere around 1.2em, depends on the browser though. That's the thing, the CSS specification doesn't say what the default distance for line-height should be because different languages might have different defaults and CSS is not specific to any single language so basically what the CSS specification says is, there should be a default and it should probably be somewhere around 1.2 and you know, that's the thing, web browsers have this tendency to do things around a line-height of 1.2, but they're not exactly the same. Every one is just a little bit different so don't rely on a specific line-height being the default. If you absolutely have to have a specific line-height, you need to go in and declare it yourself, you need to expressly say this is what the line-height is going to be.

Now, you might wonder, ok, I can have line-height 1.2em, and I can have line-height 1.2 and there's no difference there, and so Why would I, why would there be one and not the other. This is actually a little bit difficult to illustrate on the paragraph, but it easier to illustrate on the body element, and I'm going to bring things up a bit. So let's say we set our body to have a line- height of 1.5em. All right, so this is going to make the line-height of the body element 1.5 times the font size of the body element.

You notice everything sort of spread out a little bit because what happens is, let's say that the body's font size is 12 pixels, that's what it comes out to be. So whatever combination of circumstances, maybe the user has set it to be that, may be somewhere else in the style sheet we set the body font size should be 12 pixels, whatever it is, just let's assume is 12 pixels. So line-height 1.5em, would multiply that 12 pixels by 1 and a half and get a value of 18 pixels, and then, that value of 18px, 18 pixels for the line-height is what we get inherited by all the descendent elements of the body, if you recall inheritance from an earlier chapter. So H1's, Paragraphs, links whatever, they're all going to inherit that value of 18 px, because I used 1.5em, but if I just say line-height 1.5 then, what gets inherited is not that calculated line of 18 pixels, what gets inherited is the 1.5.

And so you can see, what happens there it's a small chain, but it's still noticeable. Each element multiplies its font size by 1.5, and that's what it uses for its own line-height. So if you have headings that are bigger than the rest of the text, their line- heights will be 1 and a half times their font size, which is going to be larger than one and a half times regular paragraph text. So we go back and make the body 1.5em again. Now, we're back to having the line-heights be calculated 18 pixels, and that's what gets inherited. So look, for example at about tea history, see how it shrunk down, and that's because its line-height is now 18 pixels, it's not 1.5 times its font size is just 18 pixels. Even if that about tea history thing had a font size of 60 pixels or 72 pixels, it's line-height would still be 18 pixels and that would make things kind of crowded so that's why this scaling factor the 1.5 the unitless number is recommended so strongly over things like 1.5em and certainly over pixel line-heights, I mean you can do pixel line-heights but you're really setting yourself up for a lot of anguish, because if you say line-height 15 pixels, then all the elements that descend from that element are going to pick up that line-height of 15 pixels, no matter what their font sizes are.

you could have tiny footer text, that's only 8 pixels tall and it has it's line-height of 15 pixels. So scaling factors are pretty much always preferred over united links like pixels, or ems or whatever the case might be. So that's basically a line-height for you.

Show transcript

This video is part of

Image for CSS Web Site Design
CSS Web Site Design

73 video lessons · 61073 viewers

Eric Meyer
Author

 
Expand all | Collapse all
  1. 14m 34s
    1. Welcome
      28s
    2. What is CSS?
      5m 34s
    3. Design tour
      2m 38s
    4. Using the exercise files
      1m 20s
    5. Installing the Web Developer toolbar
      4m 34s
  2. 25m 56s
    1. XHTML essentials
      3m 55s
    2. CSS essentials
      5m 17s
    3. Embedded style sheets
      2m 20s
    4. Linking a style sheet
      2m 19s
    5. Linking to multiple style sheets
      2m 20s
    6. Using linked and embedded style sheets together
      4m 21s
    7. Using imported style sheets
      5m 24s
  3. 57m 48s
    1. ID selector essentials
      6m 38s
    2. Class selector essentials
      4m 9s
    3. Best practices for classes
      4m 52s
    4. Grouped selection
      4m 2s
    5. Descendant selectors
      6m 44s
    6. The sources of style
      6m 38s
    7. Specificity
      8m 21s
    8. Making things important
      4m 32s
    9. Inheritance essentials
      5m 12s
    10. Making things really unstyled
      4m 2s
    11. User style sheets
      2m 38s
  4. 39m 3s
    1. Box model essentials
      7m 35s
    2. Simple floating
      5m 3s
    3. Using float for layout
      5m 5s
    4. Fixing column drop
      5m 35s
    5. Clearing essentials
      4m 20s
    6. Float containment
      6m 35s
    7. Creating a navbar from a list
      4m 50s
  5. 38m 3s
    1. Coloring text
      4m 13s
    2. Defining color in CSS
      8m 12s
    3. Coloring backgrounds
      6m 35s
    4. Applying background images
      4m 19s
    5. Manipulating the direction of background images
      2m 52s
    6. Positioning backgrounds
      7m 23s
    7. Background shorthand
      4m 29s
  6. 58m 28s
    1. Altering line height
      7m 32s
    2. Font style and weight
      5m 45s
    3. Sizing fonts
      9m 59s
    4. Using font families
      10m 38s
    5. Font shorthand
      6m 5s
    6. Justifying text
      4m 56s
    7. Vertically aligning text
      4m 22s
    8. Transforming text
      3m 49s
    9. Text decoration
      5m 22s
  7. 44m 40s
    1. Margin essentials
      14m 21s
    2. Adding borders
      6m 52s
    3. Padding
      9m 17s
    4. Using negative margins
      7m 19s
    5. Margin collapsing
      6m 51s
  8. 20m 38s
    1. Styling tables and captions
      5m 23s
    2. Styling table cells
      6m 30s
    3. Styling a column with classes
      4m 51s
    4. Styling links inside table cells
      3m 54s
  9. 30m 40s
    1. Styling for specific mediums
      4m 3s
    2. Creating a print style sheet
      6m 35s
    3. Hiding layout for print
      4m 11s
    4. Styling for print
      6m 34s
    5. Complex styling for print
      4m 37s
    6. Creating a footer
      4m 40s
  10. 37m 23s
    1. Getting started
      1m 11s
    2. Setting global styles
      4m 4s
    3. Defining masthead and navbar colors
      3m 27s
    4. Layout of the navlink bar
      3m 38s
    5. Using columns
      4m 49s
    6. Setting content styles
      1m 53s
    7. Creating the sidebar boxes
      5m 42s
    8. Creating the sidebar form
      3m 23s
    9. Completing the sidebar
      3m 29s
    10. Making a table
      3m 12s
    11. Creating a footer
      2m 35s
  11. 1m 28s
    1. Goodbye
      1m 28s

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 CSS Web Site Design.

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.