1

I have got this structure:

    <div id="wrapper2">
<div id="smallImages">
    <span>
       Small Image 1
    </span>
      <span>
          Small Image 2
    </span>
      <span>
          Small Image 3
    </span>
</div>  
   </div>

The problem is when I try to float the spans that are inside that div. When I float them, they get off the flow of the div.. the div actually lie above them.. Note that they all fit the divs width.

CSS:

#smallImages{
    margin:auto;
    background-color:#267990;
    width:300px;
}


#smallImages span{
    background-color:#f18e99;
    width:90px;
     height:150px;
     display:block;
float:left;
  }

why does it happen?

Dmitry Makovetskiyd
  • 6,942
  • 32
  • 100
  • 160

1 Answers1

3

Floating element are not considered when calculating the height of parent elements, if the parent's overflow is set to visible according to the CSS2 specification.

There are however CSS hacks to get around this: https://stackoverflow.com/a/11597829/384617

Community
  • 1
  • 1
David Pärsson
  • 6,038
  • 2
  • 37
  • 52
  • Can you explain..why they are not considered as part of the parent elements height? if I float an element, does it get completely out of its flow? – Dmitry Makovetskiyd Nov 04 '12 at 09:33
  • I'd say it's this way because that's the CSS definition, which can be found here: http://www.w3.org/TR/CSS2/visudet.html#normal-block – David Pärsson Nov 04 '12 at 09:49