Reputation: 2856
I have the problem that I have 3 divs and when one div is longer than the other div, it creates some whitespace.
I would like to have the whitespace gone and the divs connect.
This is what I have now:
.one{
background: lightgreen;
height: 300px;
width:100px;
float: left;
margin: 5px;
}
.two{
background: brown;
height: 500px;
width: 100px;
float: left;
margin: 5px;
}
.main{
width: 220px;
}
.info{
background: orange;
height: 200px;
width:100px;
float: left;
margin: 5px;
}
<div class='main'>
<div class='info'>
to this one
</div>
<div class='two'>
</div>
<div class='two'>
this one should be up
</div>
<div class='two'>
</div>
<div class='one'>
</div>
</div>
The only reason I have these classes is because I want to show an example of my problem, In reality all divs have the same class.
Could anyone solve the problem for me?
As you can see in my image, the bottom div is not connected to the one above it.
all divs have float: left;
Upvotes: 0
Views: 113
Reputation: 69
That is not possible, when the class .two
is floating left.
You have to use float:right
for the class .two
instead.
.one{
background: lightgreen;
height: 300px;
width:100px;
float: left;
margin: 5px;
}
.two{
background: brown;
height: 500px;
width: 100px;
float: right;
margin: 5px;
}
.main{
width: 220px;
}
<div class='main'>
<div class='one'>
to this one
</div>
<div class='two'>
</div>
<div class='one'>
this one should be up
</div>
</div>
Upvotes: 1
Reputation: 5648
You will need to float the .two
class to the right.
float: right;
Hope this helps :>
.one{
background: lightgreen;
height: 300px;
width:100px;
float: left;
margin: 5px;
}
.two{
background: brown;
height: 500px;
width: 100px;
float: right;
margin: 5px;
}
.main{
width: 220px;
}
<div class='main'>
<div class='one clearfix'>
to this one
</div>
<div class='two'>
</div>
<div class='one'>
this one should be up
</div>
</div>
Upvotes: 1