When flexbox items wrap in column mode, container does not grow its width

后端 未结 6 2113
长情又很酷
长情又很酷 2020-11-21 05:22

I am working on a nested flexbox layout which should work as follows:

The outermost level (ul#main) is a horizontal list that must expand to the right w

6条回答
  •  醉梦人生
    2020-11-21 06:14

    The Problem

    This looks like a fundamental deficiency in flex layout.

    A flex container in column-direction will not expand to accommodate additional columns. (This is not a problem in flex-direction: row.)

    This question has been asked many times (see list below), with no clean answers in CSS.

    It's hard to pin this as a bug because the problem occurs across all major browsers. But it does raise the question:

    How is it possible that all major browsers got the flex container to expand on wrap in row-direction but not in column-direction?

    You would think at least one of them would get it right. I can only speculate on the reason. Maybe it was a technically difficult implementation and was shelved for this iteration.

    UPDATE: The issue appears to be resolved in Edge v16.


    Illustration of the Problem

    The OP created a useful demo illustrating the problem. I'm copying it here: http://jsfiddle.net/nwccdwLw/1/


    Workaround Options

    Hacky solutions from the Stack Overflow community:

    • "It seems this issue cannot be solved only with CSS, so I propose you a JQuery solution."

    • "It's curious that most browsers haven't implemented column flex containers correctly, but the support for writing modes is reasonably good. Therefore, you can use a row flex container with a vertical writing mode."


    More Analysis

    • Chromium Bug Report

    • Mark Amery's answer


    Other Posts Describing the Same Problem

    • Flex box container width doesn't grow
    • How can I make a display:flex container expand horizontally with its wrapped contents?
    • Flex-flow: column wrap. How to set container's width equal to content?
    • Flexbox flex-flow column wrap bugs in chrome?
    • How do I use "flex-flow: column wrap"?
    • Flex container doesn't expand when contents wrap in a column
    • flex-flow: column wrap, in a flex box causing overflow of parent container
    • Html flexbox container does not expand over wrapped children
    • Flexbox container and overflowing flex children?
    • How can I make a flexbox container that stretches to fit wrapped items?
    • Flex container calculating one column, when there are multiple columns
    • Make container full width with flex
    • Flexbox container resize possible?
    • Flex-Wrap Inside Flex-Grow
    • Flexbox grow to contain
    • Expand flexbox element to its contents?
    • flexbox column stretch to fit content
    • https://stackoverflow.com/q/48406237/3597276
    • flex-flow: column wrap doesn't stretch the parent element's width
    • Why doesn't my
        expand width to cover all the
      • ?
      • How to have width adjust when flexbox columns wrap?
      • Flexbox wrap not increasing the width of parent?

提交回复
热议问题