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

前端 未结 5 1369
误落风尘
误落风尘 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:26

    This is something quite frequently met in just simple HTML. In you current code, you are not using any containers, wrappers or rows. This leads for the elements to overlap, if you want them not to overlap, you should give them some positioning or padding. In the provided fiddle, I have added a padding of 50 px for the divTwo in order to increase it's box show it is seen better.

    The main idea is that you never start simply writing code but carefully think about the positioning of each element on your webpage. A good practice would be to learn how to "stack" elements( That's how I call it, the term might not be correct). Another thing is that there are some certain front end frameworks which could teach you better by example how to do this.

    Bootstrap, Zurb Foundation (But Bootstrap...I'm not sure how many people use Zurb)

    Here's the JS Fiddle to see how exactly the div has changed:JS Fiddle

提交回复
热议问题