【发布时间】:2016-03-11 02:18:04
【问题描述】:
我有一个 flexbox 布局,它实际上是 3 x 3 但我可以用 2 x 2 Fiddle 来说明
.grid-container {
width: 480px; /* Max */
display: flex;
flex-flow: row wrap;
}
.grid-cell {
flex: 1;
background: #ccc;
width: 50%
}
<div class="grid-container">
<div class="grid-cell"><img src="http://www.bathfringe.co.uk/wordpress/wp-content/uploads/street-icon.jpg"/></div>
<div class="grid-cell"><img src="http://www.bathfringe.co.uk/wordpress/wp-content/uploads/street-icon.jpg"/></div>
<div class="grid-cell"><img src="http://www.bathfringe.co.uk/wordpress/wp-content/uploads/street-icon.jpg"/></div>
<div class="grid-cell"><img src="http://www.bathfringe.co.uk/wordpress/wp-content/uploads/street-icon.jpg"/></div>
<div class="grid-cell"><img src="http://www.bathfringe.co.uk/wordpress/wp-content/uploads/street-icon.jpg"/></div>
<div class="grid-cell"><img src="http://www.bathfringe.co.uk/wordpress/wp-content/uploads/street-icon.jpg"/></div>
</div>
这样可以,但图像不会随着网格变小而调整大小,如果我添加.grid-cell img { width: 100%;},则所有单元格都适合一行。如果我拿走.grid-cell {width: 50%;},也会发生同样的情况。
奇怪的是,在 Firefox 中达到了我想要的效果;网格按比例缩小。在 Chrome 和 Safari 中,即使使用 -webkit- 语法,它的行为也与上述相同。随着网格变窄和图像溢出,每个单元格的高度保持不变。
【问题讨论】: