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

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

Understanding floats

From: Dreamweaver CS5 Essential Training

Video: Understanding floats

Most CSS-based layouts are float-based layouts. That is, the majority of the elements in the layout are floated to achieve element positioning. Although floated elements are removed from normal document flow, they still affect the elements that come after them. Something that comes in very handy when building layouts. The float property has two specific values, left and right. A floated elements shifts either to the left or to the right, until its outer edge reaches the edge of its containing block or another floated element.

Understanding floats

Most CSS-based layouts are float-based layouts. That is, the majority of the elements in the layout are floated to achieve element positioning. Although floated elements are removed from normal document flow, they still affect the elements that come after them. Something that comes in very handy when building layouts. The float property has two specific values, left and right. A floated elements shifts either to the left or to the right, until its outer edge reaches the edge of its containing block or another floated element.

Elements that come after a floated element act as if it's no longer there and will move up to occupy the now empty space. In some cases this can lead to the floated element actually overlapping other items on the page. Line boxes such as individual lines of text will flow around a floated element. Even though the containing block that the lines are inside of actually flows under the floated element. This is best illustrated by imagining text wrapping around an image. Floats will continue to affect any element that comes after them until the float is cleared.

Now we'll discuss clearing later. For right now let's tackle some of the basics of floating. So here I have the floating.htm file open and this is found in the 10_03 folder. Let's take a quick look at the structure of our page. Inside of our page we have three div tags. One has an ID of box1, the other has an ID of box2, and the last one has an ID of box3. As you can see we already have some styles that are defining the width and the height of the boxes.

And we also have some margins placed on the bottom of them to hold boxes apart from each other. Well, let's go ahead and float our first element. So I am going to go up to my CSS Styles and highlight the selector #box1. That's our first div tag. Go ahead and add a property here and you want to add the float property. And we are just going to float that to the left. And if you grab the pull down menu you can see that you have left, right, none or inherit. So really those two values are what you are going to be choosing between, left and right. I want to go ahead and choose left.

And as soon as I do that something really, really odd happens to our layout. Box1 doesn't seem to move at all, in fact it's just where it was before. Box2 on the other hand seems to have gone missing. Well at least part of it has gone missing and box3 has moved up as well. So what happened here? Well what happened was, box1 was removed from normal document flow. Think of somebody just taking something off the page and picking it up so that it hovers over the page. Box2 and 3, no longer seeing a box above them, moved up to occupy that space.

So why are we still seeing the text for box2? Well we are seeing the text because the containing element went up underneath the parent. But the text itself would wrap around the floated element. And that's what we were talking about earlier when we were talking about what happened to those in-line boxes. Well let's change it to float right and see if it looks any different. So go back to the same selector, choose box1, float that to the right. And yeah that looks a little different. Now box2 and box3 are still moving up to occupy that space.

But because they are no longer touching or interacting with box1 at all, the in-line boxes move up as well and they're not trying to wrap around the element. Now let's make another more drastic change. I am going to take box1 and float it back to the left. Go ahead and highlight the selectors for box2 and box3 and for both of those add a float left property as well. Now what's happening is it looks like we have a single line of elements when in fact we know from the structure that we have three block level elements one after another.

What's happening is that remember that floated elements are going to go all the way over until they reach the edge of the containing element, or until they reach another floated element. So in this case there is plenty of room for box1, box2 and box3 to all fit on the same line. Now this is very similar to some techniques that we do in building menus for example. We will take the menu items and float them to left to form a horizontal menu bar. You could also think of these boxes as being larger, taller elements and we're very close to having a three-column layout.

So you see how flexible floats are when creating different types of layout elements on the page. Now let's change this a little bit more to reflect a layout that you guys might be a little bit more used to seeing. I am going to go up to box1 and I am going to take the float property and I am going to get rid of it. The easiest way to do this is to simply click on the float itself, make sure that's highlighted in blue and then click the trashcan icon in the CSS Styles panel. Now the reason that I cautioned you to make sure this was highlighted in blue is that if you don't, you could delete the whole rule.

And you don't want to do that. You want to make sure you're just deleting that property. Now what happens is box2 and box3 continue to float but box1 is left alone. Floats only affect the elements below them. So with box1 being part of normal document flow and box2 and box3 floating, box2 and box3 are affected by the floats. Box1 could care less. I am going to type box1 and change its width from 100 pixels to 600 pixels. Now I am going to highlight box2. I am going to leave its width at a 100 pixels but I'm also going to give it a margin to the right.

So I am going to add a property here and I am going to say margin-right 25 pixels. Notice how that's pushing one floated element away from the other one. So instead of going all the way to the edge of the floated element, it hits the margin first and it creates sort of a gutter between those two elements. I am going to change its height to 600 pixels. Finally, I am going to go to box3. And here we are going to change its height to 600 pixels as well. And I am going to change its width to 475 pixels. So now this should seem fairly familiar to you.

This is a very basic CSS-based layout. We have a single area up top that would typically be used as a header. Then we have a left column and a right column. The left column could be a sidebar or navigation; the right column would be the majority of your content. This is a very common layout technique. And although there are certainly variations on it, this is very widely used in web sites all across the web. So in this movie, we've discussed the very basics of floating. However this is by no means all you need to know in order to control floats.

In any float-based layout you'll find yourself quite often needing to restore the normal document flow. And that's where clearing comes in. In our next movie we will move a step closer to building simple page layouts by discussing clearing, and how it is often used in the context of page layouts.

Show transcript

This video is part of

Image for Dreamweaver CS5 Essential Training
Dreamweaver CS5 Essential Training

135 video lessons · 88730 viewers

James Williamson

Expand all | Collapse all
  1. 2m 57s
    1. Welcome
      1m 8s
    2. Using the exercise files
      1m 49s
  2. 7m 50s
    1. What is Dreamweaver?
      3m 16s
    2. Learning web design
      2m 22s
    3. Current web standards
      2m 12s
  3. 43m 9s
    1. The Welcome screen
      4m 5s
    2. Windows and Mac interface differences
      2m 23s
    3. The Application toolbar
      4m 7s
    4. The Document toolbar
      4m 40s
    5. Arranging panels
      8m 19s
    6. Managing workspaces
      7m 32s
    7. The Properties Inspector
      5m 54s
    8. The Insert panel
      6m 9s
  4. 25m 45s
    1. Basic site structure
      3m 11s
    2. File naming conventions
      1m 49s
    3. Defining a new site
      4m 35s
    4. Managing sites
      4m 51s
    5. Managing files and folders
      6m 36s
    6. Working with browsers
      4m 43s
  5. 27m 21s
    1. Creating new documents
      5m 16s
    2. New document preferences
      3m 6s
    3. Setting accessibility preferences
      4m 56s
    4. Working with starter pages
      3m 46s
    5. Managing starter pages
      10m 17s
  6. 30m 2s
    1. Basic tag structure
      2m 15s
    2. Adding structure to text
      8m 20s
    3. Creating lists
      9m 59s
    4. Getting text into Dreamweaver
      5m 59s
    5. Importing Word documents
      3m 29s
  7. 1h 17m
    1. Understanding style sheets
      2m 16s
    2. The anatomy of a CSS rule
      1m 48s
    3. Setting CSS preferences
      6m 36s
    4. The CSS Styles panel
      10m 2s
    5. Controlling CSS through the Properties Inspector
      5m 14s
    6. Using the Code Navigator
      7m 21s
    7. Using CSS Enable
      6m 45s
    8. Understanding element selectors
      8m 11s
    9. Understanding class selectors
      8m 49s
    10. Understanding ID selectors
      5m 59s
    11. Understanding descendant selectors
      6m 51s
    12. Attaching external style sheets
      7m 44s
  8. 1h 47m
    1. Working with units of measurement
      7m 11s
    2. Declaring font families
      9m 39s
    3. Controlling font sizing
      9m 9s
    4. Controlling weight and style
      8m 0s
    5. Controlling line height
      8m 29s
    6. Controlling vertical spacing with margins
      12m 3s
    7. Controlling spacing with padding
      5m 39s
    8. Aligning text
      8m 26s
    9. Transforming text
      5m 36s
    10. Writing global styles
      15m 42s
    11. Writing targeted styles
      17m 37s
  9. 1h 32m
    1. Understanding image types
      5m 3s
    2. Managing assets in Dreamweaver
      12m 51s
    3. Setting image accessibility preferences
      4m 20s
    4. Setting external image editing preferences
      3m 52s
    5. Placing images on the page
      7m 37s
    6. Photoshop integration
      5m 54s
    7. Modifying Smart Objects
      5m 51s
    8. Alternate Photoshop workflows
      8m 8s
    9. Modifying image properties
      11m 14s
    10. Styling images with CSS
      7m 11s
    11. Using background graphics
      9m 3s
    12. Positioning background graphics
      11m 6s
  10. 55m 16s
    1. Link basics
      3m 37s
    2. Setting site linking preferences
      2m 14s
    3. Creating links in Dreamweaver
      11m 1s
    4. Absolute links
      5m 8s
    5. Using named anchors
      11m 19s
    6. Linking to named anchors in external files
      2m 44s
    7. Creating an email link
      5m 24s
    8. Creating CSS-based rollovers
      13m 49s
  11. 1h 34m
    1. CSS structuring basics
      2m 56s
    2. The Box Model
      13m 21s
    3. Understanding floats
      6m 53s
    4. Clearing and containing floats
      8m 56s
    5. Using relative positioning
      4m 8s
    6. Using absolute positioning
      7m 18s
    7. Creating structure with div tags
      12m 7s
    8. Styling basic structure
      10m 34s
    9. Creating a two-column layout
      10m 37s
    10. Using Live View and CSS Inspect
      7m 51s
    11. Using Browser Lab
      9m 39s
  12. 56m 22s
    1. Reviewing table structure
      7m 41s
    2. Importing tabular data
      5m 13s
    3. Creating accessible tables
      9m 56s
    4. Using thead and tbody tags
      4m 0s
    5. Basic table styling
      8m 45s
    6. Styling table headers
      7m 52s
    7. Styling column groups
      4m 22s
    8. Creating custom table borders
      5m 1s
    9. Styling table captions
      3m 32s
  13. 1h 43m
    1. How forms work
      3m 0s
    2. Reviewing form design
      3m 2s
    3. Creating accessible forms
      7m 33s
    4. Setting form properties
      4m 6s
    5. The fieldset and legend tags
      4m 32s
    6. Inserting text fields
      5m 58s
    7. Inserting list menu items
      5m 26s
    8. Inserting checkboxes
      7m 50s
    9. Inserting radio button groups
      6m 22s
    10. Inserting text areas
      4m 12s
    11. Inserting submit buttons
      3m 37s
    12. Basic form styling
      12m 0s
    13. Form element styling
      8m 52s
    14. Styling form layout
      11m 49s
    15. Adding form interactivity
      2m 47s
    16. Using Spry validation widgets
      12m 49s
  14. 1h 23m
    1. Planning for templates
      10m 51s
    2. Creating a new template
      10m 37s
    3. Using editable attributes
      13m 43s
    4. Creating optional regions
      6m 23s
    5. Creating new pages from a template
      9m 17s
    6. Applying templates to existing pages
      6m 9s
    7. Working with nested templates
      7m 56s
    8. Working with repeating regions
      12m 58s
    9. Modifying templates
      5m 41s
  15. 40m 14s
    1. Behaviors overview
      3m 47s
    2. Hiding and showing elements
      9m 18s
    3. Spry overview
      4m 4s
    4. Using Spry widgets
      11m 36s
    5. Adding Spry effects
      3m 6s
    6. Using the Widget Browser
      8m 23s
  16. 28m 18s
    1. Inserting Flash files
      5m 4s
    2. Setting properties for Flash
      6m 27s
    3. Dreamweaver and Flash integration
      6m 6s
    4. Encoding Flash video
      6m 10s
    5. Adding Flash video
      4m 31s
  17. 45m 28s
    1. Running site-wide reports
      6m 33s
    2. Checking for broken links
      5m 41s
    3. Checking for browser compatibility
      8m 3s
    4. Adding remote servers
      8m 0s
    5. Uploading files
      7m 20s
    6. Managing remote sites
      9m 51s
  18. 34s
    1. Goodbye

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 changes my life forever. @JosefShutter
@lynda 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 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) 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

Are you sure you want to delete this note?


Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about 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

Sign up and receive emails about 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.