Why is the parent div height zero when it has floated children
Ordinarily, float
s aren't counted in the layout of their parents.
To prevent that, add overflow: hidden
to the parent.
Content that is floating does not influence the height of its container. The element contains no content that isn't floating (so nothing stops the height of the container being 0, as if it were empty).
Setting overflow: hidden
on the container will avoid that by establishing a new block formatting context. See methods for containing floats for other techniques and containing floats for an explanation about why CSS was designed this way.