CSS: Page Layouts
Illustration by John Hersey

Normal document flow


CSS: Page Layouts

with James Williamson

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Video: Normal document flow

When people first learn how to control page layout with CSS, they're very eager to learn about things like floating, using positioning, and other details about page-layout techniques. While this is understandable, one of the unfortunate side effects of this is that people often don't pay enough attention to one of the most important page- layout concepts of them all, and that would be normal document flow. Normal document flow is exactly what happens to your page when you do nothing at all. It's the rules that all browsers use to control the appearance of elements on the page.
Expand all | Collapse all
  1. 4m 20s
    1. Welcome
    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 16s
    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 4s
    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 22s
  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 26s
    1. Designing for flexible layouts
      2m 30s
    2. Calculating percentage values
      8m 36s
    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

please wait ...
Watch the Online Video Course 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
James Williamson

Normal document flow

When people first learn how to control page layout with CSS, they're very eager to learn about things like floating, using positioning, and other details about page-layout techniques. While this is understandable, one of the unfortunate side effects of this is that people often don't pay enough attention to one of the most important page- layout concepts of them all, and that would be normal document flow. Normal document flow is exactly what happens to your page when you do nothing at all. It's the rules that all browsers use to control the appearance of elements on the page.

It's also more powerful than most people think, so let's take a closer look at normal document flow and how it relates to page layout. And to do that I've got the normal.htm file opened, and you can find that in the 01_06 folder in your exercise files. Now the first thing I want to do is just take this page and open it up in the browser so you can see what it looks like with absolutely no styling applied to it whatsoever. Okay, so this is the page with just the browser's default styling applied to it. We have a headline up top, we have a photo gallery with about six photos in it, and then we have little section down here where I expound a little bit on normal document flow and kind of what it is.

So essentially normal document flow says that elements are going to appear at the top of the page, they are going to read left to right and they are just going to stack one on top of another. So paragraphs are going to stack on top of each other. Headings, those block-level elements will occupy their own space within the layout. So here is the heading followed by another heading, followed by a paragraph. And then in-line elements, like these images for example, will appear on a line until they can no longer fit, and then they'll break down to the next line. So this is normal document flow in a nutshell. Now, I want to show you what we can make the page look like by just applying a few block-level properties that we already know how to control.

So I am going to flip over to the finished version of this, and we are going to do this in just a moment. And this is what you can do to the exact same content through just the use of CSS styles with no "positioning properties," only the box model properties. No floating, no positioning, nothing like that. Okay, so I am going to jump back in our code, and we'll go ahead and get started on this. All right, so the first thing I want you to do is to take off the comments. So I've got some code already commented out. If you look at about line 11, that forward slash star, that's the beginning of a CSS comment.

I am going to get rid of that. And then I have to go down to the very bottom of our styles and get rid of the star forward slash. So I've just gone ahead and uncommented those out. Now before we go back up and begin working on our styles, let's take a look at the structure of the code, so we'll know what it is that we are controlling. So we have a header and inside the header element we have a single h1. Then we have two articles. The first article has a class with attribute of gallery and inside that we have a heading, a paragraph. And then we have this div tag right here but with a class of photos, and that just has that series of images inside of it.

So we have six of those images. Notice they are each 250 pixels wide. And then when you're using the div tag as a wrapper to help us control that, so we are going to control exactly how many of those images fit on a line by controlling the size of the outer wrapper around it. Following that, we have another article. Its class attribute is normal and it just has some explanatory text that goes into normal document flow and is certainly worth reading through as you work on the exercise. Okay, so I am going to go back up into my code. Now a lot of it, I kind of already pre- populated to save us a little bit of time, so I am just going to start from the top and talk a little bit about what the existing code is doing.

Our first line is telling any browser that doesn't support the newer HTML5 elements how those only should be displayed and the fact we want them treated as if they are block-level elements, so we're telling the browsers to do just that. Most modern browsers you won't have to do that with, but just in case somebody is happening to use an older browser, that line of code comes in very handy. After that, we're stripping off default margins and padding for just a serious of elements, the div tags, headings, paragraphs, and image. This is something that's called a CSS reset and we are actually going to take a closer look at CSS resets in their own movie in just a little bit.

For the time being, just understand that we are sort of telling the browsers, hey, if you are already putting margins and padding on these elements, don't. We want to control them on our own. Following that, we do the same thing to the HTML tag, which is a root-level container of our file, and we're applying a background color to that. And for our body, we're applying a little bit of padding. Notice we are applying 25 pixels' worth of padding to the bottom. That's just to hold the content on the bottom away from the bottom just a little bit. Applying just a slight bit of typographic formatting here, where we are saying, hey! Go ahead and give us your default font size and we are going to use Georgia, and then we are going to give it a background color as well.

All right, well let's add to the body selector. So, on another line inside of our body selector I am going to go ahead and set the width of the body's content to 900 pixels. So doing that, we're basically constraining all of the content on the page, and we're saying we only want it to occupy 900 pixels wide. Now the padding gets added to that, if we had padding on the right and left sides, but we don't, so this is going to be constrained to just simply 900 pixels wide. Right now, on the next line, go ahead and apply a margin and here for margin we want to do zero for margin top and bottom, so no margin top and bottom, and then auto left and right.

Okay, so what this does for us is this is a very simple technique for centering content on the page. So by saying no margin top and bottom, we're just sort of making sure that the content adheres to the top of the page. And for when we say auto for left and right, we're saying okay, the content needs to be 900 pixels wide, but on the left side and on the right- hand side, if you have any space left over, go ahead and split that space and put it equally on the left-hand side and the right-hand side, and that has the result of centering the content on the page. Okay, I am going to keep going down. And for our header element, we're going to apply a few properties to that as well.

The first I want to do is just a little bit of padding, so I am going to type in padding. I'll 20 pixels' worth of padding for the top and the bottom, and then I'll do 25 pixels' worth of padding for the left and the right, so 20 pixels, space, 25 pixels. That will give me a little room above and below at the top and the bottom of the header, and it will give me a little room side to side as well. And then we are going to give it a background color, so I am going to type in background: rgb, and the color I am going to give this is 76, 67, 65. And it's sort of that dark sort of brown gray color, if you will.

I call it ash, but I don't really know what it is. So now we've given a background color to our header, and we've got a certain amount of padding for us here. Right now I am going to go down to my article. Now remember, we have two articles on the page: the top article has a photo gallery and then the bottom article just has the sort of informative text about the normal document flow. So this is going to be very generic styling to sort of style both of those regions. So the first thing I want to do is type in some padding, and I am just going to do zero padding top and bottom and 25 pixels' worth of padding left and right. So it kind of mirrors what we are doing with the heading, as far as the left and right padding goes, and assures that content will sort of lineup, but in the header em and with those articles.

And then one last thing we are going to do to article is we are going to do is a margin-top, and here we're going to do a top margin of 25 pixels. What that will do is it will create a little bit of space above each of the articles, 25 pixels' worth of space, to give separation between the headers and their articles and the two articles themselves, okay. So I am going to go ahead and save this and before we start working on our galleries, I want to preview it. So I am going to go back into my browser and I want to preview the changes we've made. Okay, so that's a lot of changes. Now I know a lot of the work was sort of already done for us, but look what we've done. We've centered our content on the page.

We've restricted it or restrained it, I should say, to 900 pixels wide from side to side. Here is the 25 pixels' worth of padding that we've placed already coming into play, and it's looking fairly decent. So the next thing we need to do is we need to work on our photo gallery. Now one of the things I want to do for our photo gallery is I want to make sure our photos are displaying in two columns of three, and right now they're doing that. And the only thing that's controlling that right now, there is no floating that's controlling that. There is nothing controlling that other than the constraints that we've already placed on the content. Remember, these images are 250 pixels wide.

Our page is 900 pixels wide. So there is a limit as to how many of these guys can fit on a single line. Because images are in-line elements, meaning they stack from right to left until they get to the end of a page or the end of the available room for content and then they go and form the next line, we don't really need to do anything fancy to get two rows of images; we merely need to restrict the space that they are in. Since they are already sort of restricted, what we are going to work on now is sort of styling that photo gallery so that it looks maybe a little more presentable than we have it right now.

Now one of the things that we can do for that is remember we have the div tag that wraps around those images, so by controlling that div tag, we can sort of create a defined visual region for those images. So I am going to go back in our code, and that is the first we are going to tackle is this photos. Remember, that's the div tag that surrounds those guys. So what I am going to do for that is I want to type in margin: 0 and then auto. So we are doing the same thing for the photos region that we did for the page itself; we are going to center it within its container. And the photos container is that body tag, so this should be centered within that single-column layout that we have going on.

The next thing I want to do is define a width for it as well. So I am going to choose a width of 822 pixels. Now why 822? It sounds kind of how weird. Bear with me. We'll get into that when we start talking about the widths of the actual images themselves. The next thing we want to do is we want to do some padding, and we are going to give it a padding of 10 pixels all the way around, and then we are going to give it a background. And the background we are going to give this is rgb (100, 98, 102), and that's kind of a gray, if you will.

All right, so I am going to save this and again sort of update my browser. You can see what this is doing for us. It's actually right around 842 total pixels of width, because of the padding on either side, but you can see that this is the region that we want our photos in. We've got padding, 10 pixels' worth of padding going around. And now what we want to do is we want to sort of space our images in this area so that they have a little bit of space between them and that they are centered as well. Now by defining the width the way we did, we've actually helped ourselves out a little bit. And I'll be honest with you.

When I plan this out and when you plan something like this out, you are going to approach it from the images first and then figure out how much space you need. So let me tell you how I did that. Okay, so our images are 250 pixels wide each. I want to get about 20 pixels' worth of space between each of them. So what I am going to do is I am going to 10 pixels of margin around the images. Now, vertical margins collapse unless you are dealing with in-line boxes the way we are already here with images, so I'm not actually having to worry about collapsing margins. I can just go ahead and put a 10-pixel margin around these images and I'll know that I am going to get 20 pixels' worth of spacing.

I have the padding going all the way around the interior of the div tag too, so the 10 pixels of margin on the outer edges of images will combine with that padding on the div tag to give me 20 pixels' worth of space there as well. I am also going to go ahead and put a two-pixel wide border on my images, but I can't ignore that two pixels when it comes to the total width of the images. So if you have a calculator handy, you can look at it this way. Each image is now 274 pixels wide. We've got 10 pixels of margin on each side and the two pixels of border on both sides of it.

If I multiply that times three, I get 822, and 822 with the 10 pixels' worth of padding on either side gives me the total width of 842. So math, maybe we should have paid more attention to it on our school, I don't know. All right, I am going to go back into my browser, and let's go ahead and set those values on our images and see what we get. All right, so the first thing I want to do with my image is just give it a margin of 10 pixels, and then the next thing I want to do is apply that border to it, so a border of two pixels, solid, and then white. I am going to save this. I'll preview it in my browser, and as if by magic, we get exactly the spacing, we are looking for.

We get our borders around it, which helps offset the photos a little bit. And because we carefully planned the width of that, we get equal spacing all the way around and we get a nice little container there with our div tag. That is very, very nice. Now, I know that this layout is very, very simple, but it is a perfectly good, single- column layout, with no styling required, outside of the simple box model properties that we've been controlling in order to make it work. You know, when I first started out controlling page layout through CSS, I'll be honest with you guys. I really, really overdid it. Now I was trying to float or position almost every single element on the page.

I thought that somehow if I didn't, I wasn't really controlling my layout through, you know, positioning. Oddly enough, the more experience I gained through doing page layout, the more I began to rely on normal document flow to do the majority of the work for me. You know, at this point, I try to do as much possible with normal document flow and then just merely tweak the layout using floats or positioning when required. Now this approach uses less code, it's more likely to be compatible across a wider array of devices and browser versions, and requires less work on my part.

So, I know the focus of this title is on page-layout techniques, but as we work, pay attention to how important normal document flow is to the majority of our layouts.

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.

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

* Estimated file size

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


You have completed CSS: Page Layouts.

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

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 ?

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.