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

Reviewing normal document flow

From: Dreamweaver CS4 with CSS Essential Training

Video: Reviewing normal document flow

When I first started doing CSS-based layouts, I created a lot more work for myself than I needed by attempting to position everything, and I'm talking every single element on the page. It's a common mistake that many people make when they first attempt to let a CSS handle their layout. By comparison, I find that the majority of my layouts now contain only a handful of positioned or floated elements. In the discussion of strategies for CSS -based layouts, often left out of the conversation entirely is normal document flow. Most people don't discuss it because they feel that everyone inherently understands it.

Reviewing normal document flow

When I first started doing CSS-based layouts, I created a lot more work for myself than I needed by attempting to position everything, and I'm talking every single element on the page. It's a common mistake that many people make when they first attempt to let a CSS handle their layout. By comparison, I find that the majority of my layouts now contain only a handful of positioned or floated elements. In the discussion of strategies for CSS -based layouts, often left out of the conversation entirely is normal document flow. Most people don't discuss it because they feel that everyone inherently understands it.

Since one of the best layout strategies is to let normal document flow do most of the work for you, I think it's worth taking a closer look at XHTML's normal document flow. Stated plainly, most documents will read left to right, top to bottom. Block level elements such as paragraphs or headers occupy their own space within the document flow resulting in them stacking vertically on top of each other. Some block level elements can be nested inside of one another such as Div tags, but for the most part, they create new lines above and below them within the document.

Inline level elements are typically contained within a block level element and they don't stack vertically, but display from side to side and left to right. Spans and EM tags and images are examples of inline elements. A page that relies on normal document flow can be modified by changing element box model properties such as margins and padding to change how elements interact with each other. By careful consideration and planning, the bulk of your layout can be achieved without a single positioning attribute. So, here we have the 10_03 file open and what this is it's a display of some of the prints that we have available for sale on the Desolve.org site.

I'd like to lay these out in a little bit more of an attractive fashion and arrange the prints in ordered rows. We have a pretty basic page structure. We have a header region. We have an area defined for prints. These are both being done with Div tags. Then we have a wrapper div tag that wraps both of those elements as well. That's going to allow us to do define some width and center the design on the page, all sorts of fun things that we normally like to do with CSS-based layouts. So, the first thing we're going to do is start by adding a background or two to help define these regions.

So, I'm going to go over to the CSS Styles panel and we already have some of our styles in here and I'm going to select the header selector and you can see that one is empty. We don't have any properties in that yet. So, what I'm going to do is add a background property and we're going to give this a background color of #4f4872. So now we've got sort of a purple background color for our header. Now, you'll notice that the elements are butting right up against the edge of the header, they may be a little hard to read.

So, let's go in and add a couple of more properties to this. First thing we're going to do is add some padding, and that's going to keep the elements inside of it away from the edge of the header. So, we're going to go ahead and give that a padding of 1em and you can see that makes our header taller, keeps the elements away from it and it makes it look a lot more like a defined region. Now, the next thing that we're going to do is we're going to add a little bit of margin to the bottom to help push the header and these prints away from each other. So, I'm going to add another property and this time we're going to be explicit about the margin we're adding. We're going to add margin-bottom and we're going to pass 1em worth of margin underneath that.

And you can see it just pushes our prints down. So, now we have a defined header region and it's separated from the other content on the page and it's got some padding in it which helps make it look more like a singular region, and the text doesn't bud up right against the edge, cool! Now, we need to modify the content inside of it so that it reads a little easier. So, what I'm going to do is find my #header h1 and I'm going to find this color right here and you can just literally click that color chip and change that to white. I'm going to select the header of paragraph rule right underneath that and I'm going to change this color to #CCC, which is a gray.

Okay, so our header region is styled, positioned and placed exactly where we need it. It's the first element on the page, so it's going to appear on the top of the page, just as you would normally expect headers to do. Now, in our print section, we're going to need a little bit more work here. So, we have a Div tag that surrounds all of our images and that Div tag has an ID of prints. You can see we do have a print selector and currently the only thing that it's doing is assigning a background color of #333. You can see that gray background showing through here, where the prints don't really take up any additional room.

So, one of the first things we're going to do is define a width for the prints. Each one of our images is 125 pixels wide. Based upon the amount of spacing we want between these images and based on how many we want to display in a single row, we could calculate that value and set it as the value of the width for our prints. So, we're going to go ahead and do that. Grab your print selector and let's go ahead and add a width property. We're going to go ahead and give it a width of 675 pixels. Now, as soon as we do that, notice that the number of prints that it can display in a single row, changes.

We now have 5 prints to a row and that's exactly what we want because we have a total of 15. Now, we don't have any spacing between the prints right now, but notice that the defined width allows some extra spacing. So, once we start pushing our prints away from each other, they'll fill that up and we'll space them evenly inside that region. Now, I'd like the prints to be centered within our layout, and currently they're not. You can achieve centering really easily by using some margins. So, what I'm going to do is I'm going to add another property and I'm going to type in margin. I'm going to add 0 margin top and bottom and then a space and then auto-margin for left and right.

Now, we've done that centering technique before, but since we're in a chapter on layout, it really bears talking about here. Setting the right and left margin to auto is basically telling the container element, whatever space you have left, evenly divide it between the right side and the left side of this element. Because we have a defined width on the element, we know that there is going to be a little bit of extra space left over. And when we hit Enter, you'll see that it evenly distributes that from the right side to the left side, centering the element. Now, this works in almost every single browser. Some older versions of Internet Explorer seem to have a little bit trouble with it.

But as you'll see later on, when we tackle page layout, there are ways to get around that as well. Now, I'm going to add a little bit of padding. So, I'm going to add another property and we're going to add some padding and we're just going to add 5 pixels worth of padding. That's going to help us achieve even spacing and make sure that our images don't bud up right against the edge of that, which is going to give us a little bit of framing all the way around our images. Well, now we need to tackle the spacing of the prints themselves and so what we're going to do is create a brand-new selector targeting the images inside the prints. So, you can just go ahead and select one of those if you'd like and choose a new CSS rule.

If you don't have compound selector chosen in the pull-down menu, go ahead and grab it and you should see this result, #wrapper #prints image. So, I'm going to make that less specific so that the selector just reads #prints image. So, you're targeting any image inside of an element with an ID of prints. We're going to define it in this document only and I'm going to go ahead and click OK. Now, this is going to be a very simple selector. We're just going to go to our box model and we're going to apply 5 pixels worth of margins all the way around it. I'm going to go ahead and click OK and now our prints are spacing evenly.

So, because we have placed 5 pixels worth of margin all the way around our images, we're getting consistent spacing. Now remember our 5 pixels worth of padding on the outer edge is too. So, if I do a Save All and preview that in my browser, you can see that we're getting a nice, even amount of spacing all the way around our prints. Okay, so really the only thing we have left to tackle is the footer and maybe giving a defined page size. Right now, the header element is stretching all the way across the page, for example, maybe we don't want that. So, let's tackle our footer first. I'm going to go to the #footer selector and I'm going to add a couple of more properties.

So, I'm going to close my Files panel here so I have a little bit more room. I'm going to choose Add Property and I'm going to add the background property. We're going to give this a background of #666, which is a gray, there we go. I'm going to add padding property and give it 10 pixels worth of padding so that the text doesn't bud right up against the edge of that. We're going to go ahead and give it a margin to the top, so the top margin, margin-top of 10 pixels. That's going to push the footer away from the prints and you can kind of see that occurring right here.

And then finally, we're going to change the color to white, so you can just click the color chip and change it to white and you can see our text is now reversing out. Of course, the nice thing is the padding. It is giving us enough spacing and actually driving the height of our footer. So, our footer height right now is calculated based upon the height of the text and the padding on the top and the bottom's edges. We could also center the footer text if that's what we wanted. So, I'm going to do a Save All and preview that in my browser and our layout is really coming together. The only thing that we don't have going on right now is it feels a little weird having the header stretch all the way to the edge of the page and the footer stretch all the way to the edge and having the prints sort of in here in the middle.

So, I'd like to restrict the width of these by controlling my wrapper div tag. Now, this is a very common strategy in CSS layouts. You're going to have a Div tag which can be sometimes referred to as container or wrapper or outer wrapper. And what it does is it wraps the entire content just inside the body text. We can now use this to set a defined width, background colors, background images, we can center the layout on the page this way. So, it's a really good practice and it's a practice that you'll see consistently across multiple CSS layouts.

So, what I'm going to do is add a new selector and this is just going to be #wrapper. So, if you haven't selected it beforehand, you can just select ID and type in #wrapper or, chances are, if you had it highlighted like I did, Dreamweaver will go ahead and populate that for you. Okay, I'm going to go ahead and click OK and we're going to define the width of our page at 800 pixels. So, I had to take a few things into consideration, for example, the width of my print region, I want to make sure that there is enough width for it to fit in there and for the prints to still kind of float in the middle. I'm basically determining how much spacing I want on the right and the left side of my prints now.

I'm going to go ahead and give it a margin right and so I'm going to de-select Same for all. Margin right of auto and a left margin of auto and as we know that's going to center it within the page. I'm going to apply a background color to it. So, I'm going to go to my Background and I'm going to give it a background color of #fff. That's going to be white and it's going to give our content region a white background while the page is still going to have this sort of cream background color. So, I'm going to click OK, save the file and preview that in our browser, cool! Now, this layout probably isn't going to be winning any design contest, but it does demonstrate that normal document flow can be counted on for consistent cross-browser compliant performance.

This layout is going to work in whatever browser you open it up in and you don't have to worry about any CSS hacks or tricks. That's something that any CSS designer will tell you is worth its weight in gold. So make sure that as you're going through this chapter and really focusing on laying out your pages with CSS, that you pay proper attention to normal document flow. Many times, it can take a lot of the work away from you and make the positioning that you need to do to achieve your final layout extremely minimal.

Show transcript

This video is part of

Image for Dreamweaver CS4 with CSS Essential Training
Dreamweaver CS4 with CSS Essential Training

120 video lessons · 41635 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 7m 50s
    1. Welcome
      1m 18s
    2. Do I need to know CSS to use Dreamweaver?
      2m 15s
    3. Using the exercise files
      1m 30s
    4. Setting up a custom workspace
      2m 47s
  2. 1h 2m
    1. Separating structure from presentation
      4m 14s
    2. Adding meaning with ID and class attributes
      7m 50s
    3. Understanding basic selectors
      11m 10s
    4. Understanding complex selectors
      11m 21s
    5. Examining the Cascade
      10m 16s
    6. Understanding order of inheritance
      5m 2s
    7. Understanding specificity
      5m 43s
    8. Using Dreamweaver to resolve conflicts
      7m 4s
  3. 52m 48s
    1. Working with starter pages
      2m 1s
    2. Defining fixed, elastic, liquid, and hybrid
      6m 3s
    3. Understanding starter page structures
      6m 25s
    4. Modifying CSS globally
      8m 58s
    5. Moving CSS between files
      12m 31s
    6. Preparing custom starter pages
      10m 9s
    7. Creating custom starter pages
      6m 41s
  4. 1h 25m
    1. Designing with CSS in mind
      3m 13s
    2. Using Fireworks to create site prototypes
      2m 41s
    3. Defining page structure
      8m 52s
    4. Creating the initial layout
      10m 24s
    5. Page creation and asset sharing
      11m 20s
    6. Using common libraries to create site prototypes
      5m 11s
    7. Building interactive prototypes
      17m 6s
    8. Optimizing images in Fireworks
      11m 47s
    9. Exporting web graphics from Fireworks CS4
      2m 43s
    10. Exporting interactive prototypes
      3m 11s
    11. When to export XHTML and CSS from Fireworks CS4
      8m 34s
  5. 48m 28s
    1. CSS workflows in Dreamweaver
      1m 17s
    2. Using the CSS Styles panel
      5m 12s
    3. Setting CSS preferences
      9m 50s
    4. Understanding Dreamweaver's CSS visual aides
      3m 50s
    5. The Code Navigator
      6m 5s
    6. Controlling CSS with the Properties Inspector
      8m 52s
    7. Using Related Files
      4m 35s
    8. Working with Live view
      4m 12s
    9. Working with the Reference panel
      4m 35s
  6. 1h 13m
    1. Declaring font families
      4m 57s
    2. Creating custom font family declarations in Dreamweaver
      6m 0s
    3. Understanding units of measurement
      6m 14s
    4. Controlling font sizing
      8m 41s
    5. Controlling line spacing
      7m 20s
    6. Controlling vertical margins
      7m 52s
    7. Horizontally aligning text
      3m 16s
    8. Vertically aligning text
      5m 30s
    9. Vertically centering block-level elements
      10m 31s
    10. Setting column width
      3m 33s
    11. Using font shorthand notation
      9m 15s
  7. 1h 10m
    1. Background properties
      4m 33s
    2. Using background images
      5m 16s
    3. Controlling background image tiling
      5m 33s
    4. Positioning background images
      4m 42s
    5. Using percentage values for positioning
      5m 10s
    6. Creating custom list bullets
      5m 23s
    7. CSS drop shadows
      7m 40s
    8. Image replacement techniques
      7m 24s
    9. Adding screen-only content
      7m 51s
    10. Complex background graphics
      9m 10s
    11. Using CSS Sprites
      8m 0s
  8. 38m 48s
    1. Reviewing table tag structure
      4m 48s
    2. Using thead and tbody for styling
      5m 45s
    3. Styling table captions
      4m 30s
    4. Styling headers
      8m 29s
    5. Styling table content
      4m 18s
    6. Creating alternating row colors
      3m 29s
    7. Using pseudo-class selectors for tables
      2m 27s
    8. Creating custom table borders
      5m 2s
  9. 43m 37s
    1. Examining form structure
      3m 26s
    2. Styling fieldset and legend elements
      7m 42s
    3. Styling form elements globally
      6m 31s
    4. Using classes to identify form elements
      5m 55s
    5. Styling user feedback
      6m 10s
    6. Adding user interaction
      2m 52s
    7. Styling Spry form validation fields
      11m 1s
  10. 44m 48s
    1. Using lists for navigation
      1m 40s
    2. Creating horizontal menus pt. 1: Stripping list styling
      3m 28s
    3. Creating horizontal menus pt. 2: Displaying links horizontally
      3m 54s
    4. Creating horizontal menus pt. 3: Styling links
      5m 25s
    5. Creating horizontal menus pt. 4: Rollovers
      3m 48s
    6. Creating horizontal menus pt. 5: Indicating current page
      3m 48s
    7. Creating horizontal menus pt. 6: Modifying cursor usage
      2m 11s
    8. Creating horizontal menus pt. 7: Positioning menus
      3m 8s
    9. Styling vertical menus pt. 1: Vertical menu considerations
      6m 42s
    10. Styling vertical menus pt. 2: Defining width for link elements
      4m 46s
    11. Styling vertical menus pt. 3: Using background graphics with navigation
      5m 58s
  11. 1h 40m
    1. Box model review
      7m 4s
    2. Understanding margin collapse
      7m 15s
    3. Reviewing normal document flow
      11m 0s
    4. Understanding floating
      8m 56s
    5. Containing and clearing floats
      9m 26s
    6. Understanding relative positioning
      5m 30s
    7. Understanding absolute positioning
      5m 29s
    8. Understanding the AP Elements panel
      11m 57s
    9. Understanding fixed positioning
      2m 24s
    10. Using Dreamweaver to define document structure
      10m 11s
    11. Creating a two-column layout
      17m 1s
    12. Using Dreamweaver's Design-Time style sheets
      3m 49s
  12. 28m 59s
    1. Introducing Spry widgets
      2m 18s
    2. Updating the Spry framework
      45s
    3. Examining the default Spry styles
      6m 36s
    4. Modifying tabbed panels through CSS
      5m 18s
    5. Styling Spry widgets
      8m 49s
    6. Organizing Spry style sheets
      5m 13s
  13. 34m 49s
    1. Creating print style sheets
      2m 57s
    2. Assigning media types
      3m 29s
    3. Styling type for print
      9m 21s
    4. Suppressing element printing
      3m 29s
    5. Controlling page breaks
      8m 39s
    6. Using @media blocks
      3m 5s
    7. Creating alternative style sheets
      3m 49s
  14. 35m 22s
    1. Using Dreamweaver's Browser Compatibility Check
      3m 58s
    2. Fixing code errors with Adobe's CSS Advisor
      4m 45s
    3. Strategies for browser compatibility
      5m 8s
    4. Implementing browser compatibility
      8m 18s
    5. Formatting code for deployment
      3m 15s
    6. Creating modular style sheets
      3m 38s
    7. Assembling modular style sheets
      6m 20s
  15. 38s
    1. Goodbye
      38s

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 Dreamweaver CS4 with CSS Essential Training.

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.

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.