Explanation on CSS float overflow property

前端 未结 2 1627
陌清茗
陌清茗 2021-01-21 16:49

I am a newbie to CSS. I started exploring CSS float property. I have two

elements inside a container. The two divs have equal
2条回答
  •  死守一世寂寞
    2021-01-21 17:15

    What is happening here is because:

    .container{
      overflow:hidden;
    }
    

    What is happening? Your floating div wants to take up space before your other div. Because your non-floating div has display: block, it wants a whole line to render itself. The floating div is pushing down your non-floating div which is then hidden by the style above. If you change display to inline-block, it will take up only the space it needs using the width and height properties.

    Here is an example: http://codepen.io/anon/pen/LVpxZy

提交回复
热议问题