Reputation: 3804
html,
<div id="content">
<div id="left">left</div>
<div id="right">right</div>
<div id="bottom">bottom</div>
</div>
css,
#content {
border:1px solid black;
}
#content > div {
height:100px;
box-sizing:border-box;
-moz-box-sizing:border-box;
}
#left {
float:left;
width: 50%;
border-right:1px solid black;
}
#right {
float:right;
width: 50%;
}
#bottom {
border-top:1px solid black;
clear: both;
margin-top: 50px;
}
demo
i want to make some space, after left and right div in bottom div
but if i use clear:both, margin-top isn't working.
any good idea?
Upvotes: 1
Views: 1579
Reputation: 1
You need to do the following:
Now, the margin-top: 50px of bottom div will be applied.
Further, adjust the width of both divs, make them lesser than 50%, based on how much space you want to add around these divs.
Upvotes: 0
Reputation: 8171
Yes, you are right clear:both;
. It's because clear:both
makes the element drop below any floated elements that precede it in the document.
But if you make your div display:inline-block
with cover width:100%
. It's take margin.
Upvotes: 0
Reputation: 15709
Clear floats after left,right.
Try:
HTML:
<div id="content">
<div id="left">left</div>
<div id="right">right</div>
<div class="clr"></div>
<div id="bottom">bottom</div>
</div>
CSS:
#bottom {
border-top:1px solid black;
margin-top: 50px;
}
.clr{clear: both;}
Upvotes: 3
Reputation: 441
I have updated your fiddle jsfiddle.net/saBE2/5/
The problem is that is doesn't look right with the margin because you don't have any border at the bottom for left and right boxes, also try and put margin under boxes left and right.
#content {
border:1px solid black;
}
#content > div {
box-sizing:border-box;
-moz-box-sizing:border-box;
}
#left {
float:left;
width: 50%;
border-right:1px solid black;
border-bottom:1px solid black;
margin-bottom:50px;
}
#right {
float:left;
width: 50%;
clear:right;
border-bottom:1px solid black;
}
#bottom {
border-top:1px solid black;
clear: both;
margin-top: 50px;
}
Upvotes: 0
Reputation: 2265
Use clear
to clear foat like below
.clear{height:0px !important;clear:both;margin:0 !important;padding:0 !important;}
<div id="content">
<div id="left">left</div>
<div id="right">right</div>
<div class="clear"></div>
<div id="bottom">bottom</div>
</div>
Upvotes: 0