这是我的演示,以说明我的意思:
* {
box-sizing: border-box;
}
body, html {
height: 100%;
width: 100%;
}
body {
background: #333;
margin: 0;
padding: 0;
}
.content {
display: flex;
height: 100%;
padding: 20px;
}
.panel {
flex: 0 0 200px;
display: flex;
margin-left: 20px;
}
.widget {
background: white;
width: 100%;
height: 100%;
}
.videoContainer {
display: flex;
flex: 1 1 100%;
flex-wrap: wrap;
}
.video {
height: 50%;
width: 50%;
padding: 2px;
position: relative;
}
.videoCover {
position: absolute;
background: red;
opacity: 0.4;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
img {
width: 100%;
height: 100%;
object-fit: contain; /* Default for videos */
}
<div class="content">
<div class="videoContainer">
<div class="video">
<div class="videoCover"></div>
<img width="600" height="400" src="http://thatgrapejuice.net/wp-content/uploads/2016/03/rihanna-thatgrapejuice-mariah-carey-billboard-600x400.jpg">
</div>
<div class="video">
<img width="600" height="400" src="http://www.radioandmusic.com/sites/www.radioandmusic.com/files/images/entertainment/2015/09/28/rihanna-%2812%29.jpg">
</div>
<div class="video">
<img width="600" height="400" src="http://m.buro247.com.au/thumb/600x960_0/images/640-rihanna-charity1.jpg">
</div>
<div class="video">
<img width="600" height="400" src="http://hjb.hu/wp-content/uploads/2014/02/rihanna2.jpg">
</div>
</div>
<div class="panel">
<div class="widget"></div>
</div>
</div>
垂直或水平调整浏览器大小,可以清楚地看到问题。所以基本上我想把红色封面完全放在图像上。所以我假设我需要一个与图像大小完全相同的 div。似乎对象拟合做得很好,但正因为如此,我不能放置在红色 div 上。
可以做纯css吗?我应该如何修改dom和css?非常感谢!
澄清我想要实现的是: