Reputation: 1288
Why content 3 and content 4 are not two separate divs? How can I fix it only with css? I would like the first red to be bellow the green ones and the second red to be bellow the first red.
JSFIDDLE - http://jsfiddle.net/LsgsE/
HTML
<div class="left">TODO write content1</div>
<div class="left">TODO write content2</div>
<div >TODO write content3</div>
<div>TODO write content4</div>
CSS
div {
width: 200px;
height: 200px;
background-color: red;
}
div:after {
clear: both;
display: block;
content: "";
height: 0px;
}
div.left {
float: left;
background-color: green;
}
Upvotes: 0
Views: 98
Reputation: 449
Try wit this:
div {
width: 200px;
height: 200px;
background-color: red;
clear: both;
}
div.left {
float: left;
background-color: green;
clear: none;
}
Upvotes: 1
Reputation: 825
You can solve it by adding a wrapper to your divs:
<div id="upper_block">
<div class="left">TODO write content1</div>
<div class="right">TODO write content2</div>
<div class="left">TODO write content3</div>
<div class="right">TODO write content4</div>
</div>
And set new rules in your css:
#upper_block {
width: 400px;
}
div {
width: 200px;
height: 200px;
}
div.right {
float: right;
background-color: green;
}
div.left{
float: left;
background-color: blue;
}
Upvotes: 0