CSS: How do I clear a floated object just one level and not to the left?
I'm not sure if I described this correctly. I want the object among all floats to clear, but not all the way to the left.
#parent {
background: greenyellow;
width: 500px;
height: 700px;
padding: 15px;
}
#parent>div {
float: left;
}
#object1 {
width: 40px;
height: 300px;
background: blue;
}
#object2 {
width: 100px;
height: 100px;
background: red;
}
#object3 {
width: 100px;
height: 100px;
background: purple;
}
<div id="parent">
<div id="object1">
</div>
<div id="object2">
</div>
<div id="object3">
</div>
</div>
As in the jsfiddle. I want the purple box to be below the red box. And I don't want to shrink my parent width. And I dont want to contain red and purple inside the div.
Is there a way for this. Thanks?
+3
source to share
3 answers
Set the bottom width for the parent,
#parent {width: 200px;}
http://jsfiddle.net/db0xacps/1/
Or wrap the right elements, the styles will be the same as yours.
<div id="parent">
<div id="object1"></div>
<div>
<div id="object2"></div>
<div id="object3"></div>
</div>
</div>
0
source to share