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

前端 未结 10 952
灰色年华
灰色年华 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条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 05:39

    W3Schools recommendation:

    put overflow: auto on parent element and it will "color" whole background including elements margins. Also floating elements will stay inside of border.

    http://www.w3schools.com/css/tryit.asp?filename=trycss_layout_clearfix

提交回复
热议问题