Demo and example
Float property makes the ELEMENT1 is placed in outside of his parent, like this example.
ELEMENT1
Solved float property is like this example.
ELEMENT1
So how to solve that?, it's easy you just need to add clear: both before and after the floated element and inside the parent. Like this example below.
Before:
<div style="background: #ccc; border: 1px solid #999; padding: 5px;">
<div style="float: left;">
ELEMENT1
</div>
</div>
<div style="float: left;">
ELEMENT1
</div>
</div>
After:
<div style="background: #ccc; border: 1px solid #999; padding: 5px;">
<div style="clear: both;">
</div>
<div style="float: left;">
ELEMENT1
</div>
<div style="clear: both;">
</div>
</div>
<div style="clear: both;">
</div>
<div style="float: left;">
ELEMENT1
</div>
<div style="clear: both;">
</div>
</div>
Or like this if you have two floated element in a row
<div style="background: #ccc; border: 1px solid #999; padding: 5px;">
<div style="clear: both;">
</div>
<div style="float: left;">
ELEMENT1
</div>
<div style="float: right;">
ELEMENT2
</div>
<div style="clear: both;">
</div>
</div>
<div style="clear: both;">
</div>
<div style="float: left;">
ELEMENT1
</div>
<div style="float: right;">
ELEMENT2
</div>
<div style="clear: both;">
</div>
</div>
you just need to add clear both, remember that!
Tiada ulasan:
Catat Ulasan