New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

CSS: Page Layouts
Illustration by
Watching:

Column height considerations


From:

CSS: Page Layouts

with James Williamson

Video: Column height considerations

In the previous layout examples we've been forcing our columns to be fixed height so that we can visualize our sample layouts a little bit better. Now, in practice, the height of columns is typically determined by the content inside of them. Now, most of the time designer simply factor this into their design and build layouts that work with a natural height of columns. But what happens if you need a column to stretch to match the height of another column, or if you want it to take up all the vertical space available? Well, in those cases you're going to have to carefully plan your layouts around those requirements, and you'll need to understand exactly how browsers calculate the height of elements.
Expand all | Collapse all
  1. 4m 20s
    1. Welcome
      54s
    2. How to use the exercise files
      3m 26s
  2. 1h 39m
    1. Box model review
      8m 47s
    2. Calculating element dimensions
      11m 11s
    3. Understanding margin collapse
      7m 59s
    4. Calculating em values
      7m 41s
    5. Calculating percentage values
      7m 51s
    6. Normal document flow
      13m 3s
    7. Controlling element display
      8m 53s
    8. Using CSS Resets
      7m 11s
    9. Fixed, fluid, and responsive layouts
      9m 9s
    10. CSS debugging tools
      6m 46s
    11. Using the Firebug Inspector and the WebKit Web Inspector
      11m 5s
  3. 53m 15s
    1. Page design workflow
      3m 6s
    2. Page design tools
      4m 56s
    3. Determining page structure
      7m 18s
    4. Creating image assets
      8m 58s
    5. Creating initial page structure
      7m 3s
    6. Adding meaning with classes and IDs
      5m 23s
    7. Structuring content with HTML5
      6m 6s
    8. Building internal structure
      10m 25s
  4. 1h 36m
    1. Floating elements
      7m 50s
    2. Clearing floats
      7m 28s
    3. Containing floats
      7m 50s
    4. Clearfix technique
      10m 38s
    5. Floating inline elements
      14m 34s
    6. Two-column floated layouts
      8m 17s
    7. Three-column floated layouts
      11m 30s
    8. Column height considerations
      7m 3s
    9. Creating equal-height columns
      10m 42s
    10. Floats: Lab
      5m 25s
    11. Floats: Solution
      5m 21s
  5. 51m 42s
    1. Relative positioning
      7m 59s
    2. Absolute positioning
      8m 59s
    3. Fixed positioning
      4m 23s
    4. Controlling stacking order
      8m 31s
    5. Clipping content
      8m 21s
    6. Controlling content overflow
      5m 38s
    7. Positioning elements: Lab
      3m 59s
    8. Positioning elements: Solution
      3m 52s
  6. 48m 46s
    1. Design considerations for fixed layouts
      3m 28s
    2. Establishing the layout grid
      7m 57s
    3. Defining column spacing
      9m 30s
    4. Applying the grid through CSS
      8m 56s
    5. Creating grid-based assets
      8m 26s
    6. Grid design resources
      6m 22s
    7. Building fixed layouts: Lab
      4m 7s
  7. 44m 35s
    1. Designing for flexible layouts
      2m 30s
    2. Calculating percentage values
      8m 45s
    3. Setting flexible width values
      6m 6s
    4. Making images flexible
      8m 10s
    5. Setting minimum and maximum widths
      7m 24s
    6. Building flexible layouts: Lab
      4m 53s
    7. Building flexible layouts: Solution
      6m 47s
  8. 49m 36s
    1. Responsive layout overview
      3m 49s
    2. Using media queries
      7m 16s
    3. Organizing styles
      8m 39s
    4. Making content responsive
      8m 33s
    5. Mobile design considerations
      7m 32s
    6. Building responsive layouts: Lab
      4m 23s
    7. Building responsive layouts: Solution
      9m 24s
  9. 1h 22m
    1. Creating multi-column text
      6m 36s
    2. Using borders to enhance design
      13m 59s
    3. Rounding corners
      6m 56s
    4. Adding drop shadows
      10m 35s
    5. Working with opacity
      6m 8s
    6. Utilizing the background property
      15m 5s
    7. Working with CSS sprites
      7m 58s
    8. Enhancing page design: Lab
      6m 22s
    9. Enhancing page design: Solution
      8m 38s
  10. 6m 25s
    1. Additional resources
      6m 25s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
CSS: Page Layouts
8h 57m Beginner Feb 07, 2012

Viewers: in countries Watching now:

CSS: Page Layouts introduces basic layout concepts, gives advice on how to create properly structured HTML based on prototypes and mockups, and goes into critical page layout skills such as floats and positioning. Author James Williamson shows how to combine these techniques to create fixed, fluid, and responsive layouts. Designers are also shown how to enhance their pages through the creative use of CSS techniques like multi-column text, opacity, and the background property. Exercise files are included with this course.

Topics include:
  • Reviewing the box model
  • Calculating em and percentage values
  • Controlling how elements display
  • Creating fixed, fluid, and responsive layouts
  • Structuring content with HTML5
  • Floating elements
  • Using relative, absolute, or fixed positioning
  • Defining column spacing
  • Creating grid-based assets and layouts
  • Considering mobile-design-specific issues
  • Working with multi-column text
  • Enhancing page design CSS Sprites
Subjects:
Web Web Design
Software:
CSS
Author:
James Williamson

Column height considerations

In the previous layout examples we've been forcing our columns to be fixed height so that we can visualize our sample layouts a little bit better. Now, in practice, the height of columns is typically determined by the content inside of them. Now, most of the time designer simply factor this into their design and build layouts that work with a natural height of columns. But what happens if you need a column to stretch to match the height of another column, or if you want it to take up all the vertical space available? Well, in those cases you're going to have to carefully plan your layouts around those requirements, and you'll need to understand exactly how browsers calculate the height of elements.

So before we can get into specific layout techniques around controlling element height, I want to take a closer look at how browsers calculate height itself. If I scroll down, I can see it's a very simple structure. So inside the body tag we have a section here, and we just have a paragraph inside of that. If I preview that in my browser, you can see that right now the body's width is set to 960 pixels and the section's width is set to 50%. Now, the reason for that is, once we start stretching these columns, I want you to be able to tell what's the body and what's the section.

Now, most people's misunderstanding of height comes from them understanding what happens with width, and let me show you that really quickly here. So I go into the file and I remove the width of the body and I remove the width of section and preview that in a browser, what happens is both the body stretches to 100% and any block-level content inside of it, in this case the section, stretches to 100% as well. So the default for block-level elements inside the browsers if no width is defined, they're just going to stretch out to be 100% the width of their parent element, in this case the entire viewport.

So a lot of times designers, when they set height to 100%, they're expecting the same behavior, that the column will just go ahead and stretch to the height of the window, and when that doesn't happen, it kind of confuses them, so let's go and take a look at that. So I am going to go back into my code here, and I am just going to undo those widths. I sort of need those so that we can see what's going on. I'm going to come down here to section and I am just going to set section's height to 100%. So I am going to save that, preview that in my browser, and bam, nothing.

Well, that's not absolutely true. So what's happening here is that the height of an element is set to auto by default. What that means is is the contents of the element defines its height. So in this case, body's height is being defined by the content inside the section. So when I tell the section to be 100%, it's saying be just as tall as the body. The body is getting the height from the section, so in essence, we're saying be 100% of yourself.

It might be fulfilling, but it doesn't work the way we anticipate it. So what we have to do is we have to go in and set explicit heights on every single parent element above the one that we are targeting. So if I come in for body and I say height 100%, unfortunately, that doesn't work either, because there is another tag above body and, yes, that's the HTML tag. So if I come here and say, okay, height 100% on the HTML tag as well, now if I save this and test it, yay, everything is stretching, including the body and including our section.

Now, all seems well, but it just sort of seems well. Remember, it's stretching to the height of the viewport, which means the height of the available space, so what happens if the content is longer than that? So if I come down, for example, here to my section and I grab this paragraph and copy it. Let's say I am going to paste it a few times. One, two, three, four, five, six, seven should be enough. So if I save this and go back into my browser and test it, you can see it's still stretching to 100% of the height.

But when happens when I scroll? Oh, hmm. So the initial column height and the initial body height is the height of the viewport. So when I begin to scroll, that height that was fixed at that size no longer stretches to fit the viewport, so now my column is just sort of overflowing here. So that is really not what I'm wanting. So if I go back into my section, however, and instead of section I say height 100%, what if I said minimum height, meaning, is the shortest it can be as 100%.

So if I save this, and go back in and test it, aha, now it stretches, but unfortunately, the body doesn't. If I go back into the body and tell its minimal height to be 100% as well, trying this method, you're almost always sort of chasing your own tail. Now, the other reason this works--and I am just going to scroll back up at the top and do that again--is because we don't really have any padding or anything like that. If I go back in and reduce this content-- and I am not going to get rid of all of it. I just want to get rid of about half of it. And if I go back up to my section here, and I add say some padding.

So if come in and add padding of 10 pixels. Now, here's the thing about using percentages for both height and width. When you do a padding of 10 pixels, height is added to that. Those effects are cumulative. So the 10 pixels' worth of padding top and 10 pixels' worth of padding on the bottom are added to that 100% height; they're not factored into it. So if I save this, again, test it in my browser, what happens is is even though the content doesn't stretch all the way down, you see we've got a page that can scroll and this is still overlapping, and that's that extra spacing that we are getting through our padding.

So it's really frustrating. Now, we have a really simple layout here. As our layouts get more and more complex, these issues that we are taking a look at right now, they magnify, because you're going to have to start dealing with the height of several elements above this one. So does this mean that you should never try to have elements' content stretch to fit the screen, or its parent? No, that's not what it means at all. But you really need to understand how height works in order to properly plan and execute that type of layout. Typically, for example, there is a lot of wrapping div tags and things like that involved to keep some of those negative side effects from happening.

Now, I recommend checking out a few gallery sites online. A few of my favorites are cssbeauty.com, where you can look at some sample sites that designers have submitted. Pattern Tap, which is awesome. They have different patterns for footers and buttons and sidebars and headers and all sorts of really cool things. There is the bestcssvault.com, which is, again, user-submitted sites. And you could even go to like wordpress.org and check out some of their sample themes. Now, what you're going to find, almost overwhelmingly, is that most designers simply design their sites so that variable-height columns don't negatively impact it.

Sometimes knowing the limitations of a technique is just as important to designing it as knowing its strengths.

There are currently no FAQs about CSS: Page Layouts.

 
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.
Upgrade now


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 Upgrade now

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: Page Layouts.

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

Notes cannot be added for locked videos.

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.