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

前端 未结 5 1956
无人及你
无人及你 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条回答
  •  Happy的楠姐
    2020-12-29 02:26

    As suggested by Mahks, you can make the flex container inline. But if laying it inline is not suitable for your layout, an alternative is to float the flex container (not the flex items).

    Floats will shrink-wrap to fit their contents, and this is no different for a block-level flex container. An inline-level flex container behaves similarly to an inline-block box when laid out in its parent inline formatting context, which means it will also shrink to fit its contents by default.

提交回复
热议问题