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

Floats: Solution

From: CSS: Page Layouts

Video: Floats: Solution

Well, I hope you had a good time working on the lab and getting our two-column fixed layout to its finished state. In this movie, I am going to show you how I styled the elements that you were tasked to finish in the lab. Feel free to compare your solution to mine, and remember, especially with floats, there are multiple ways that you could have achieved the same layout. So I am just going to go over our main.css file, and I have got the index.html opened here as well. These are found in the finished files directory within the 03_10 folder. So I am just going to get right into each one of the steps of our lab.

Floats: Solution

Well, I hope you had a good time working on the lab and getting our two-column fixed layout to its finished state. In this movie, I am going to show you how I styled the elements that you were tasked to finish in the lab. Feel free to compare your solution to mine, and remember, especially with floats, there are multiple ways that you could have achieved the same layout. So I am just going to go over our main.css file, and I have got the index.html opened here as well. These are found in the finished files directory within the 03_10 folder. So I am just going to get right into each one of the steps of our lab.

I am going to scroll down to about line 160 or so, where our basic layout styles are. So the first thing that we were asked to do was take the body and set its width to 1280 pixels, and then the next thing was to center that content as well. So to center the content, I gave it a margin of 0 for top and bottom and then auto for left and right. Remember, that splits the available space in the viewport equally to the left and right-hand sides, centering the content. Now the next thing was to create our two columns.

So in this case, I wrote a selector for article, I floated article to the left, I gave it a width of 850 pixels, and gave it a padding left of 50 pixels. So the 850 pixels plus the additional 50 pixels gives us the 900 total pixels that we need for that column. I used padding instead of margin, and margins certainly would have worked and would've been preferable had I had a background color behind the article, but since I didn't, padding works just fine. And even though I'm not as worried about Internet Explorer 6 anymore, there's an older Internet Explorer 6 bug where if you apply the margin to the same direction that you have a float, it doubles that margin.

There are ways around that, but one of the easiest ways around it is just not doing it, so I have sort of gotten into that habit over the years, and so I am using padding there instead of margins. Now if I look at the aside, it's very similar. I'm floating it to the right. Now remember, we could have floated it to the left and added a little bit of right margin to the article, but for me, it's much easier to go ahead and just float that to the right. So it's going to go all the way to the right edge of the containing element, which is the body. And I gave it up a padding-right of 50 pixels, so same thing here. I gave padding-left, here I used padding-right to hold the content of 50 pixels from the edge of the containing element.

I had to calculate exactly how much space I had left and since I started with 900 pixels, I can subtract 1280 by 900 and it let me know how much space I had remaining. And I wanted to have 50 pixels' worth of space on the right-hand side--that's my padding--and 50 pixels' worth of space between those two columns, which leaves me with 280 pixels of available space for my aside, and that becomes the assigned width for it. For the page footer, in order to make sure the page footer stays below both of those columns, I simply set the clear property to both. Remember, that's going to reestablish normal document flow and it guarantees that the page footer is going to be at the very bottom of the page.

Now the last thing that we had to focus on were those two interior elements, the news sections. So I am going to scroll down and show you guys how I handled those. All right, so about line 351 in the finished file. So for news, essentially what I did is I floated both of them to the left, and then I gave them a margin-right of 50 pixels. So that's going to make both of them appear horizontally, side by side. It's also going to space them apart by 50 pixels. But there is a downside to doing it this way, and the downside is is that both of them now have a right margin of 50 pixels.

So although it's going to space them 50 pixels apart, it's also going to push the right one maybe further away from the edge than I wanted it to be. So to deal with that, I created another selector here, and I used the sibling selector that says, hey, when a item with the class of news follows immediately after another item of the class of news, set its margin right to 0, and just sort of canceled that out. So I used a very specific selector to target that element. There are certainly other ways of doing it. There are probably more efficient ways of doing it, if I want to be honest with you guys, but that is certainly one way to achieve that.

And I'm going to go ahead and preview the index file in a browser, so we can see our finished results. As I scroll down, here is our two-column layout. Here are the two interior elements with their two columns. Notice that we have 50 pixels' worth of space on either side of our article, and aside; we have 50 pixels' worth of space between these two guys; and then we have another 50 pixels' worth of space here for the gutter. So notice that right-hand margin is not negatively impacting that. And then our footer is forced down at the bottom of our columns, exactly the way that we wanted it to.

You know you can see from doing this lab that it doesn't really take a lot of CSS to create floated layouts. I mean, I know there are other elements within the layout that we didn't style, and those certainly required a little bit of work, but we handled the main content regions: The article, the aside, the footer and then some of those interior elements as well, like these two news items. So hopefully, one of the things that you can see from this lab is not only how easy it is to use floats to create layouts, but how efficient it is to let normal float handle the bulk of the layout. The only thing we're really floating are these two main page elements.

All of the other main structural elements are being handled through normal document flow. And that sort of describes the strategy that I use, which is to let normal flow handle the bulk of the layout, and then use floats to adjust and create columns when necessary.

Show transcript

This video is part of

Image for CSS: Page Layouts
CSS: Page Layouts

71 video lessons · 44156 viewers

James Williamson
Author

 
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

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: 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 preferences from 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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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.