Everyone who plays web programming has gone through this:
.children {
float: left;
}
<div class="parent">
<div class="children">
Teste
</div>
</div>
If you use Inspect Element above you may notice that in element .parent
height
is 0px
.
I have never read why this happens. This is part of the question, if anyone knows and can explain it, it would be good.
But what do I do to solve this? Something I learned a while ago so I did not have to use clear: both
:
.parent {
display: table;
}
.children {
float: left;
}
<div class="parent">
<div class="children">
Teste
</div>
</div>
You may now notice that the .parent
element has the same height as .children
, even with float
. Although I have been doing this for some time and it helps me a lot, I would like to know why this happens.
What is the effect of table
on float
?