Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
As covered earlier in this course, the CSS float property is critical for multiple column layouts. The same property can be used to modify the design of content areas. You'll recall that the float property takes an element out of the document flow, moves it to the right or left, and allows text to wrap around it. Let me show you two different uses of the float property. First we'll take a look at the final version of the page we're going to be working on and as I scroll down you can see the first of the float elements, which is this pullQuote here on the left, and then as I move down, you'll see a very common use of the float property, as it's applied to an image, which in this case is floated to the right of an unordered list.
Okay, let's close this out, so we can get started on building that ourselves. The first thing I'm going to do is position my cursor in between these two paragraphs here and I'll place my cursor right at the start of that second paragraph. And now I'm going to insert a div, so I'll go up to the menu this time, choose Insert>Layout Objects>Div Tag, and I wanted to go at the insertion point. Now this is going to be a class, because I could use multiple pullQuotes on the page. So I'm going to enter in just pullQuote, notice that in this circumstance I don't need to put in a leading period for class or leading pound sign for ID, I just put in the class name.
We haven't defined the CSS Rule for a pullQuote yet, but I can do that right from this dialog box. So I'll just click New CSS Rule, and when that dialog box comes up, it has pre-chosen class as a Selector Type, which is correct, entered in the .pullQuote name for the selector name, also correct, and asks if I want to keep it in the Main.CSS, and I do. So we'll click OK, now I have a number of properties that I want to assign to the pullQuote to make it really standout.
I'm going to choose a different kind of type here, let's go with Trebuchet MS, Arial, Helvetica, sans-serif for the Font-family. I'm going to make it 18 pixels tall, so that it will standout quite a bit, let's give it an Italic font style. Now color-wise I'm going to choose the darker brown color here that we see in the California logo, and I'm ready to go to the next category, which is Background, and let's give it a background color that blends in with the same background color as I call out.
Next, we want to go to the Box category, where we can set the width of our floated item. As with the columns, you always want to set a width for any floated element, so this will be 200 pixels Wide, and we're going to Float that to the left, I do want to give it some padding around it to make it standout from the wrapped around text, but I don't want it to be all of the same. So I'll deselect Same for all under Padding and we'll put in 10 for the Top, 10 for the Right, 5 for the Bottom, and 10 for the Left.
Next, I want to add in a Margin Right value to give a little additional space on the right-hand side, and I'm going to give it 10pixels. Finally, let's go to the Border category, and I only want a Top and a Bottom border, so let's deselect all of the Same for all options here, and in the Top we want that to be a solid line, 3 pixels thick, and the same brown that we see in the type.
Same thing for the Bottom, solid, 3 pixels and then the same brown, which we can sample right from the color swatch, okay? Click OK and then click OK and you'll see that it comes in even with the standard Dreamweaver content placeholder text. Let's go ahead and replace that now and I'm going to type in an opening quote, and, "What a wonderful experience! Our family had the best time!" Now I also want to include brief line saying where this is from, so this is going to be from let's say a woman named Ashley S, and in this paragraph I wanted to give it a particular class, so I've highlighted the paragraph from the tag selector, and I'm going to open up that tag using my Quick Tag Editor.
So I'll press Command+T, and after a space type in class, and let's call this testimonial. Now we need to create some rules to handle the design of this callout a little bit better. So the first one I want to address is the actual paragraph that we see here. We want to tighten that up somewhat. So I'm going to create a New CSS Rule, let's make it a little less specific. It will always appear within our main article however, and then click OK.
And I'm going to set the Line-height to 24, so it's not quite a double spacing, and then go over to Box where I can deselect Same for all under Margin, and set the Margin Bottom to 0, so we can tighten up that space between the testimonial and the top of the line there. Click OK, and that goes part of the way there. Let's go into testimonial, now let me select the paragraph with the class testimonial and create another new rule. Again, make that a little bit less specific and all I want to do here is align the text to the right, and you do that in the Block category.
Okay, And there's our pullQuote. Now let's go down and we'll add in the image. So we want that to appear just to the right of this listing, so I'm going to place my cursor right in front of the text that's part of our H3 heading and then choose Insert>Image and it's called olives.jpg, and there it is. So we'll click that and give it the alt text of Olives. Now I'm going to give this a particular class, so that I can control it.
Again, I'll select it and then go down to Image and select that from my Tag Selector and press Command+T to bring up the Quick Tag Editor or Ctrl+T if you prefer on the PC, and let's put in a class of articleImage. Now my article image has already been previously defined to Float right, so that I can collect that find that again, because I assume that there are other article images here. So sometimes you'll encounter a situation where there's already a mechanism setup for you.
A class if you will that you can then plug-in and it will have the necessary padding; in this case the padding is 1em from the Top, 0 on the Right, 1em on the Bottom, and 1em on the Left. Let's take a look at this in Live View, my callout looks pretty good, my pullQuote looks pretty good, and the image here looks pretty good as well. If your floated elements are in the middle of the content, as these two examples are, you probably won't need to clear the floats.
However, if there's a chance that they will expand beyond the containing element, it's best to add an overflow auto property to the container to handle that issue.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.