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

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

CSS: Page Layouts
Illustration by

Two-column floated layouts


From:

CSS: Page Layouts

with James Williamson

Video: Two-column floated layouts

Now that we've had some time to become familiar with the concepts of using floats and how they affect surrounding elements, I want to show you a few common approaches for creating float-based layouts. I'm going to start with the most common layout, and that is a two-column layout. Now we're going to be doing three different versions of exactly the same layout. So the same HTML structure, we're just going to do it three different ways. And that's really to show you guys that often it's a personal choice as to how you control the layouts.
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

Two-column floated layouts

Now that we've had some time to become familiar with the concepts of using floats and how they affect surrounding elements, I want to show you a few common approaches for creating float-based layouts. I'm going to start with the most common layout, and that is a two-column layout. Now we're going to be doing three different versions of exactly the same layout. So the same HTML structure, we're just going to do it three different ways. And that's really to show you guys that often it's a personal choice as to how you control the layouts.

Okay, so we have three files that I've opened up here. If you look in the 03_06 directory, you're going to find 2col_v1, 2col_v2, and 2col_v3. Just go ahead and open all three of them up, so that you know the structure of the page that we're going to be working with here. Very simple structure, just some basic building blocks if you will. Inside the body we have a header, which is typical. We have a section, which is going to be our first column. We have an aside, which is the sidebar. It's going to form our second column. And then finally, at the bottom we have a footer.

So that's a pretty basic page layout: header at the top, two columns side to side, footer at the bottom. If I go back up to our body tag, I can see that the width of the page is set to a fixed value of 960 pixels. So what we're going to do is we're going to have a left column that is 640 pixels wide and a right column that is 300 pixels wide, and that's going to leave us with 20 pixels' worth of space between the two columns, or a 20-pixel gutter for you designers out there.

So the first method of doing this is what I call float one margin for the other. And so for our first column, column1, I'm going to come in and I'm going to go ahead and float column1 to the left. The next thing I'm going to do is give it a defined width, because we want our column to be a specific size. I'm going to give it a width of 600 pixels. Now I know I said, hey, the left column is going to be 640 pixels, so I'm also going to do some padding and the padding is going to be 20 pixels. So remember, 20 pixels to the left, 20 pixels to the right, of padding, adds up to a total of 640 pixels.

Okay, if I save this and preview this in one of my browsers, you can see what happens here. This is where the really important stuff goes. This is where the related content goes. So here's my left column. Here's my sidebar. Now the problem is the sidebar is coming up underneath, so we're basically seeing both that and the footer slide up underneath the left column here. So I'm going to go back into my code, and I'm going to start styling my column2. So for column2, what I'm going to do here is I'm going to set padding to 20 pixels as well, so a consistent padding all the way throughout.

And instead of setting a defined width on column2, what I'm going to do is I'm going to do a margin-left. What margin-left is going to do for me-- think about what's happening here. column2 is right now sliding up underneath column1. By applying a wide enough margin on the left-hand side, I'm creating enough empty room for that left-hand column to display. So what I'm going to do for the margin- left is a really big value, 660 pixels. That's 640 pixels for the width of the column on the left-hand side and then another 20 pixels for gutter space right there in the middle.

Now for our footer, one of the things we're always going to do for our footer is we're going to go ahead and clear that. So I'm just going to type in clear: both. Now the reason for that is you don't want the footer sliding up underneath the left column as well. So I'm going to save that, go back into my browser, refresh, and you can see, there's our two-column layout. Footer at the bottom, and then we have a ton of left margin over here for this column, and we give it just enough to create that extra 20 pixels' worth of space. So that's version 1. Now I'm going to go over to 2col_v2.htm, and we're going to start styling that one.

Okay, now for this one, we're going to float both columns, and we're going to float both of them to the left. So if I go down into my code for column1, it's going look very similar. I'm going to go ahead and float that to the left. I'm going to go ahead and give it a width of 600 pixels and give it padding of 20 pixels on both sides. So that gives us a total of 640 pixels, and we're floating that to the left. Now for column2, I'm going to come in also and float that column to the left.

The next thing I'm going to do is I'm going to give it a padding of 20 pixels as well, and this time I'm going to give it a width of 260 pixels. Now if you think about this, 260, and we've got 20, so it gives me 300 pixels worth of space there. I've got 640 pixels here. But the one thing I don't have is the gap, the gutter, the space between them. And when you're dealing with two elements floating side by side, one of the best ways to get that is just use a margin. So for column1, I'm going to come up and apply a margin-right of exactly the value we need, which is 20 pixels, so there's our gutter.

So if I save this and preview this in our browser as well, you can see it's working perfectly, except for the footer, which is now stretching all the way up underneath that. So remember, we always have to go down to that footer and clear it. And so I'm going to ahead and Clear Both. So if I save that and preview it again, now the footer is in its right place, and I've got my columns. Now the thing about using this approach where you're floating one to the left and then you float another one to the left, it works just fine, but the big problem here is going to be column drop.

Column drop happens when the content no longer fits within that space. So that could be content overflowing out of one of the columns. It could be that we just got the math wrong. So if I go back into this, if I just tweaked it a little bit, for example, if I come into the column2 and I change the width to 270 pixels that's just 10 pixels' worth of difference here, and I preview that, you can see the second column drops because now there's no longer any space for it over here. So using this type of a layout, you need to be very, very precise with your measurements and make sure that your content inside of this is going to adhere to those boundaries as well.

So let's do our last version, 2col_v3, and this happens to be my personal favorite. We're still going to float both of the columns, but we're going to float one to the left and we're going to float the other one to the right. So I'm going to scroll down and find column1. And for that, we're going to float that to the left, we're going to give it a defined width of 600 pixels, and we're going to give it a padding of 20 pixels. Now the thing I like about this is we're going to let the defined widths of the two columns determine how wide the gutter is.

We don't need to worry about margins. We don't need to worry about it because we're going to take column 2 and instead of floating it to the left, we're going to float that to the right. Next thing, we're going to do is we're just going to go ahead and give it 20 pixels' worth of padding, just as we did before, and we'll set the width to 260 pixels. But notice this time I'm not having to set any margin on it to sort of push it over in place. By floating it to the right, it's automatically going to snap to the right-hand side. And that of course means that if the body increases in size, the only thing that's really going to happen negatively is that my gutter is going to get a little bit wider. All right! The next thing I need to do is come down to my footer, just clear both, save that.

And if I preview this in my browser as well, you can see there is my two-column layout. Here's the method we just tried, there's the method of floating both of them to the left, and there's the method of floating one to the left and using margins. Now visually, if I tab through these, can you tell the difference? No, of course not. They look exactly the same, but they're using three very different methods to achieve the same layout. As I mentioned, I really do prefer that last method, but really this lesson isn't about what my preferences are; it was about showing you multiple techniques that you can use.

Now in many cases, the source order of your content, in terms of the order that it's encountered or the complexity of your page, might drive you to use one of these methods over another. Now most of the time, it's just personal preference, but by understanding exactly how these techniques work, you're going to be better prepared to react to circumstances where you have to be a little creative in order to achieve the correct results.

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.