🚨 Heads up! This course is no longer supported. We recommend checking out our Webflow Essentials course.
How to float a div tag
Questions
Student Gallery
Be the first to share something.
Course info
Overview
- You'll need a laptop (Mac or PC)
- Dreamweaver CC installed. Dreamweaver can be downloaded from theAdobe website here.
Can I use this tutorial with Adobe Dreamweaver CS4, CS5 or CS6?
Daniel Walter Scott
Founder of Bring Your Own Laptop & Chief Instructor
I discovered the world of design as an art student when I stumbled upon a lab full of green & blue iMac G3’s. My initial curiosity around using the computer to create ‘art’ developed into a full-blown passion, eventually leading me to become a digital designer and founder of Bring Your Own Laptop.
Sharing and teaching are a huge part of who I am. As a certified Adobe instructor, I've had the honor of winning multiple Adobe teaching awards at their annual MAX conference. I see Bring Your Own Laptop as the supportive community I wished for when I was first starting out and intimidated by design. Through teaching, I hope to bring others along for the ride and empower my students to bring their stories, labors of love, and art into the world.
True to my Kiwi roots, I've lived in many places, and currently, I reside in Ireland with my wife and kids.
Downloads & Exercise files
Transcript
To do that, make sure you're on main css. Scroll through until you find the div tag called text. And then in here you can see I can change it from 700 to uh, from 900 to 700. All right, it's made a little smaller to fit my image diviv tag. Great. So let's put the image div tag that's gonna go on the right hand side here.
It's gonna insert Diviv tag. Where is this one gonna go? This one's gonna go after my text box. Okay, this, we're gonna have an ID of image. Let's click. Okay, kind of works.
It's definitely after the text box I can check and code view, um, and go to source code. You'll see there's my container. It's wrapping everything out. Then there's my header. It opens and closes. Then there's my nav, which opens and closes, text opens and closes.
And there's my last one, the image. So it's right after it, but it's not filling the gap over here. So we need to look at something called float to make that happen. Let's first of all style our image div tag, just like we did with the rest of them. Let's go to main, let's click a selector. And this one's called image.
Okay, image enter. So we have a width of pixels. What's left is 3 24. Okay, so it's the right width, so it should fit in there, but it's not, that's okay. Let's give it a height. Let's match the height of the last one, which I think was about 400 pixels.
So it's the right height. Let's pick a background color and let's pick orange. All right, let's make it a more orange. Orange. Great. So it's, it's there but it's not underneath.
So we need to look at something called float now. So we need to do two things. We need to float this guy called text ID to the left. And we need to float the orange to the right and that will make them sit side by side. So we're gonna play around with text first. So make sure you're in CSS, find the text and you're gonna scroll down until you find float.
So it's a little bit down here. There it is, there. Float. I'm gonna float him to the left. And something strange happens if I click float, you'll notice the orange box kind of disappeared. It slipped underneath the green box and The text is squid out on the side here.
So don't worry about that. Um, it's a two step process. You need to float the text box to the left and the image box to the right. So once we've done that, it all should come back to normal. So under main CSS, I wanna find the image box and I'm gonna float this one to the right. And there he is.
He pops up next to this guy. Alright, so float is used for putting div tags side by side. I could have 10 div tags and keep floating them. Left, left, left, left, left, left, left. And they're all stack up next to each other. Okay?
So it doesn't matter how many you actually have, you can use, um, the float to get them to stack up next to each other. In the next tutorial, we'll look at clearing the float, which means putting something underneath these two. So, alright, I'll see you in the next tutorial.
How do you put two divs side by side in Dreamweaver?
Give both divs widths that fit within their container, then use the CSS float property. In this example, set the text div to 700 pixels wide and float it left, then set the image div to 324 pixels wide and float it right. Both boxes will sit alongside each other.
How to Float Div Tags Side by Side in Dreamweaver
Key Takeaways
Resize an existing div by editing its rule in main.css.
Insert the second div after the first, keeping both inside the same container.
Use left and right floats to turn stacked boxes into a two-column layout.
Do not panic if the layout looks odd after applying only the first float.
Understand why clearing floats is the next step when adding content underneath.
We’re working with a page that already has a container, a header, a navigation area and a green text box. The aim is to make room for an orange image box on the right. First, we need to adjust the existing text div. Then we can add the new div and use floats to bring the two together.
1. Make Room by Resizing the Text Div
The green text box is currently too wide at 900 pixels. We need to reduce it to 700 pixels so there is space beside it for the image area.
Select main.css in Dreamweaver.
Find the CSS rule for the div with the ID text, shown as #text.
Change its width from 900px to 700px.
Great. The green box is now narrower, leaving a gap on the right. That is where the image div will eventually sit, but creating enough space is only the first part of the job.
Reducing the text box to 700 pixels leaves room for the image area.
2. Insert the Image Div After the Text Div
Use Insert Div Tag to create the next box. Set its position to come after the text div, and give it the ID image. Click OK.
At this stage, the new div appears after the text box, but it does not fill the gap on the right. That is expected. Its position in the HTML is correct; we have not yet applied the CSS that will place it alongside the green box.
Check the structure in Code view
If you want to check where the new div has gone, switch to Code view and open the page’s source code. The structure should have:
An outer container wrapping the page sections.
A header div with its own opening and closing tags.
A navigation div with its own opening and closing tags.
The text div, opened and closed.
The image div immediately after the text div.
The image div belongs after the text div, not inside it. Checking the closing tags helps confirm that these are two separate boxes within the same container.
3. Style the Image Div
Back in the CSS controls, select main.css and create an ID selector for #image. Give the new box these settings:
Width: 324 pixels, which is the remaining space in this example.
Height: 400 pixels, to match the text box.
Background colour: orange, so it is easy to distinguish from the green text area.
The image area is just a coloured div for now. Its name identifies its role in the layout; we are not inserting an actual image at this stage.
Once styled, the orange box is visible underneath the green one. It has the right dimensions, but it still needs a float setting to move into place.
The orange div has its size and colour, but it still sits below the text div.
4. Float the Text Div to the Left
Now we can work on the side-by-side layout. Start with the green text box:
Select the #text rule in main.css.
Scroll through its CSS properties until you find float.
Set float to left.
Something a little strange can happen here. The orange box may seem to disappear underneath the green one, while its text gets pushed into the space at the side.
Don’t worry. For this layout, applying the floats is a two-step process. We have floated the text box, but the image box still needs its own setting.
After the first float, the layout looks unfinished because the image div has not been floated yet.
5. Float the Image Div to the Right
Next, select the #image rule in main.css. Find the same float property and set it to right.
There it is. The orange box moves up next to the green box, giving us the two-column layout we wanted.
With the text floated left and the image area floated right, both boxes sit side by side.
The finished settings are:
Text div: 700 pixels wide, 400 pixels high and floated left.
Image div: 324 pixels wide, 400 pixels high and floated right.
The important distinction is that HTML order and visual placement are separate things. Inserting the image div after the text div gave us the right structure. Applying the CSS floats gave us the side-by-side arrangement.
Using More Floats and Adding Content Below
Floats are not limited to two boxes. You could have several divs, each floated left, and they can line up beside one another while there is enough horizontal space. The widths still need to fit the available area.
The next issue is placing something underneath the floated boxes. That is where clearing floats comes in. For now, the key is to get both columns into position: resize the first div, add and style the second, then apply the float to each one.
Key Terms
Div
An HTML element used to group content into a section or box. Here, separate divs form the container, header, navigation, text area and image area.
ID selector
A CSS selector that targets an element by its ID. The selectors #text and #image let us style the two boxes separately.
Float
A CSS property that positions a box towards the left or right of its containing area. This example uses opposing floats to place two divs alongside each other.
Clearing floats
Controlling how later content sits in relation to floated elements. It is the next concept needed when placing a section below these columns.
FAQs
Why is my image div underneath the text div?
Adding a div after another div does not automatically place it beside that div. In this example, first set the widths, then float the text div left and the image div right.
Why does the orange box disappear when I float the text box?
This is the intermediate state after applying only the first float. Select the image div’s CSS rule and float it right to complete this layout.
Can I float more than two divs?
Yes. Multiple divs can be floated left to line up beside one another, provided there is enough horizontal space for their widths.
Written by Daniel Walter Scott — Founder of Bring Your Own Laptop & Chief Instructor