How do I set a flex-container to be the width of its flex-items?

前端 未结 5 1971
无人及你
无人及你 2020-12-29 01:40

I have a flex container with justify-content: flex-start. There ends up being overflow on the right side due to the flex items taking less space than the size o

5条回答
  •  猫巷女王i
    2020-12-29 02:35

    not sure about your question, but:

    DEMO: http://jsfiddle.net/jn45P/

    you just need to enable the flexibility on the flex items, using flex-grow:1; to fill up the space

    a
    a
    a
    a
    a
    a
    a
    a
    a
    a
    div.o { border:2px red solid; padding:2px; width:500px; flex-direction:row; display:flex; justify-content:flex-start; } div.o > div {border:2px red solid;margin:2px;} div.o.flex > div {flex:1 1 auto;} /* enable flexibility on the flex-items */

提交回复
热议问题