通过图片的宽高比设置父元素的paddingBottom
实现
/* html */
<div
className='waterfall-item-img'
style={{ paddingBottom: `${data.composite_preview.height / data.composite_preview.width * 100}%` }}
>
<img src={data.composite_preview.url} alt='' />
</div>
/* css样式 */
.waterfall-item-img{
position: relative;
}
img {
position: absolute;
width: 100%;
left: 0;
right: 0;
z-index: 2;
}