【发布时间】:2018-09-07 18:18:41
【问题描述】:
在我们的电子商务项目中,所有照片都是正方形。所以有些产品的顶部和底部有很多空白。我不想在不编辑照片(数千张)的情况下“削减”那个空间。我几乎达到了我的目标。但父 DIV 延伸到 IMG 的基本 100%。
.container {
box-sizing: border-box;
width: 100%;
padding: 0 40px;
}
.main-header {
height: 80px;
width: 100%;
background-color: grey;
}
.product {
display: flex;
flex-flow: row nowrap;
margin-top: 20px;
}
.media {
flex: 1;
background-color: grey;
margin-right: 20px;
}
.landscape {
object-fit: cover;
width: 100%;
height: 60%;
}
.purchase {
width: 160px;
background-color: grey;
}
<div class="container">
<header class="main-header">
</header>
<content class="product">
<div class="media">
<img class="landscape" src="https://cdn.shopify.com/s/files/1/0286/1214/products/Trance-3-Color-B-Neon-Green.jpg">
</div>
<div class="purchase">
</div>
</content>
</div>
【问题讨论】: