Reputation: 73
Hi I have a little css float problem.
I have 3 floating div's. As viewed below
<div style="width : 200px;">
<div style="float : left; width : 90px; height : 50px; ">div 1</div>
<div style="float : left; width : 90px; height : 90px; ">div 2</div>
<div style="float : left; width : 90px; height : 50px; ">div 3</div>
</div>
What I want is that div number 3 is floating up in the empty space below div 1.
Is that possible with css?
Upvotes: 0
Views: 962
Reputation: 499
I think your best bet is wrapping div 1
and div 3
on a <div>
then floating that to left. Like the following code:
<div style="width : 200px;">
<div style="float: left;">
<div style="width: 90px; height: 50px;">div 1</div>
<div style="width: 90px; height: 50px;">div 3</div>
</div>
<div style="float: left; width: 90px; height: 90px;">div 2</div>
</div>
Upvotes: 0
Reputation: 6541
float your div 2 to the right not left.
And write your css properly, not as style in the div
.b{float : right; width : 90px; height : 90px;}
You can then get rid of space by changing the size of the holding div, or add padding-right:20px; or margin-right:20px; depending what you want. Difference between padding and margin for a different post.
.b{float : right; width : 90px; height : 90px; margin-right:20px;}
Upvotes: 4
Reputation: 3117
Use below snippet
<div style="width : 200px;">
<div style="float : left; width : 90px; height : 50px; background-color: blue; ">div 1</div>
<div style="float : left; width : 90px; height : 90px;background-color: red; ">div 2</div>
<div style="float : left; width : 90px; height : 50px;background-color: green; margin-top:-40px; ">div 3</div>
</div>
The below code will also do the same.
<div style="width : 200px;">
<div style="float : left; width : 50px; height : 50px; background-color: blue; ">div 1</div>
<div style="float : left; width : 90px; height : 90px;background-color: red;float:right; margin-right:60px;">div 2</div>
<div style="float : left; width : 50px; height : 50px;background-color:green; ">div 3</div>
</div>
Back ground color is added to see the divs.
Upvotes: 0