Floating elements within a div, floats outside of div. Why?

前端 未结 10 1094
灰色年华
灰色年华 2020-11-22 05:10

Say you have a div, give it a definite width and put elements in it, in my case an img and another div.

The idea

10条回答
  •  萌比男神i
    2020-11-22 05:25

    There's nothing missing. Float was designed for the case where you want an image (for example) to sit beside several paragraphs of text, so the text flows around the image. That wouldn't happen if the text "stretched" the container. Your first paragraph would end, and then your next paragraph would begin under the image (possibly several hundred pixels below).

    And that's why you're getting the result you are.

提交回复
热议问题