max-height: 400px
指定整个网格的约束。但是子元素超出了限制,尽管它们应该height
相对于父元素的大小进行拉伸。
https://codepen.io/Alexxxsander/pen/XWOGedj
<div class="grid">
<div class="grid__col">
<img src="https://biggardenfurniture.com.au/wp-content/uploads/2018/08/img-placeholder.png" alt="">
</div>
<div class="grid__col">
<img src="https://biggardenfurniture.com.au/wp-content/uploads/2018/08/img-placeholder.png" alt="">
</div>
<div class="grid__col">
<img src="https://biggardenfurniture.com.au/wp-content/uploads/2018/08/img-placeholder.png" alt="">
</div>
<div class="grid__col">
<img src="https://biggardenfurniture.com.au/wp-content/uploads/2018/08/img-placeholder.png" alt="">
</div>
<div class="grid__col">
<img src="https://biggardenfurniture.com.au/wp-content/uploads/2018/08/img-placeholder.png" alt="">
</div>
<div class="grid__col">
<img src="https://biggardenfurniture.com.au/wp-content/uploads/2018/08/img-placeholder.png" alt="">
</div>
</div>
* {
box-sizing: border-box;
}
.grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
outline: 2px solid royalblue;
max-height: 400px;
gap: 10px;
}
.grid__col {
height: 100%;
}
.grid__col:nth-child(2) {
grid-column: 2 / 3;
grid-row: 1 / 3;
}
.grid__col:last-child {
grid-column: 3 / -1;
}
.grid__col img {
display: block;
width: 100%;
max-width: 100%;
height: 100%;
object-fit: cover;
}