Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

flex布局时,flex-direction: column;且内部含有图片时shrink失效

以下代码,期望两个div带着图片,自动shrink到height为150px。
实际在chrome中会超出#container元素
请问这是为什么?
image.png

<style>
  #container {
    display: flex;
    width: 100px;
    outline: 1px solid blue;
    height: 300px;
    flex-direction: column;
  }

  #container div {
    width: 100%;
    height: 200px;
    flex-shrink: 1;
  }

  #container div img {
    width: 100%;
    height: 100%;
  }
</style>

<body>
  <div id="container">
    <div>
      <img src="./test.png">
    </div>
    <div>
      <img src="./test.png">
    </div>
  </div>
</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

确实是有问题,纵向 grow是生效的,shrink确实不生效,我去查了文档,在grow中强调了image.png

而shrink并没有类似说明,应该是不支持高度自适应image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...