Why does the background of a floated element appear to move independent of the content?

前端 未结 5 1370
误落风尘
误落风尘 2021-01-24 10:45

In the CSS code below, it appears that the background of divTwo has moved behind divOne. But the content of divTwo appears to have been le

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-24 11:39

    Like @ZobmbieChowder said, the logic of CSS float property is that you have a huge box which contains two smaller boxes, and now you want one is located on the left and another on the right. If you don't have the huge box first, the complier doesn't get human's logic which one shall be the left or right. It only makes sense for machine that you "define" a container first, then talk about its element position left or right.

提交回复
热议问题