Why inline-flex element with clearfix has a weird white space?

前端 未结 3 1520
花落未央
花落未央 2020-12-31 20:12

I have a weird behaviour of an inline-flex element when applying a clearfix to it. When I set a clearfix to an element which has an inline-flex dis

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 20:36

    You have to imagine your page as a flow. Every element of your page is in the flow (DOM). You are using the position property to change the position in the flow.

    block

    A block element will Always start a new line. (ie: div)

    inline-block

    Inline blocks elements are blocks like div but with inline properties in it. (ie: span)

    inline-flex

    This is used the same way as inline-block in the flow. It makes a container that is inline but with the flex layout.

    For your example, an interesting thing to do in order to focus on the difference between inline-block and inline-flex is to add text in your child div. You'll see that the comportment of your child div will once again change because it has text in it. JSFiddle example

    EDIT : I found a sentence on SO that resumes well the situation. thank's to @BoltClock on This post :

    display: inline-flex does not make flex items display inline. It makes the flex container display inline.

提交回复
热议问题