How to get a div with extrinsic height and intrinsic width inside a flexbox

前端 未结 4 1379
长情又很酷
长情又很酷 2021-01-21 03:53

Problem

Say we have a vertical (i.e. flex-direction: column) flexbox container with a given width and height. The flexbox contains divs and each div contains an image.<

4条回答
  •  感动是毒
    2021-01-21 04:21

    Given the example snippet, I assume you want the red bordered container to be just as big as the inner image. The black bordered container should not change in size.

    To accomplish this, it is enough to add display: flex; to #imagecontainer.

    You have set some flex properties on it (flex-basis and flex-shrink) that do nothing without a flex element.

    By default, the display value of a div is block.

    Snippet:

    Image in flex container with limited height
    
    Original image

    Image in just a simple div with limited height

提交回复
热议问题