为什么<img/>不会缩小项目缩小,但div flex项目呢?

时间:2017-01-05 17:19:33

标签: css flexbox

鉴于以下标记和css(fiddle here),为什么第二个.bingo div符合它的父母高度,但不符合<img>

<div class='root1'>
  <div class='child'>
    <img class='bingo' src="http://www.audubon.org/sites/default/files/styles/engagement_card/public/sfw_apa_2013_28342_232388_briankushner_blue_jay_kk_high.jpg?itok=ttMfUhUu">
  </div>
</div>

<div class='root2'>
  <div class='child'>
    <div class='bingo'></div>
  </div>
</div>

和css:

.root1, .root2 {
    display: flex;
    height: 150px;
    justify-content: center;
    flex-direction: column;
}
.root1 {
  background-color: lightgreen;
}
.root2 {
  background-color: lightblue;
}
.child {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    position: relative;
}
.bingo {
    display: block;
    object-fit: contain;
    flex-grow: 1;
    border: 1px solid black;
}

div.bingo {
  background-color: pink;
}

0 个答案:

没有答案