我无法将我的图像填充到单个div中,堆叠在一起。好像他们放在一行
@keyframes fade {
0% {
opacity: 0;
}
11.11% {
opacity: 1;
}
33.33% {
opacity: 1;
}
44.44% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.fadein {
position: absolute;
height: 200px;
width: 400px;
display: inline-block;
background-size: contain;
overflow: hidden;
border: 4px solid #2e7645;
background-size: cover;
background-position: center;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
/** outline: 1px solid blue; **/
}
.fadein img {
max-width: 100%;
max-height: 100%;
z-index: -1;
position: relative;
left: 0;
right: 0;
opacity: 0;
animation-name: fade;
animation-duration: 9s;
animation-iteration-count: infinite;
}
.fadein img:nth-child(1) {
animation-delay: 0s;
}
.fadein img:nth-child(2) {
animation-delay: 3s;
}
.fadein img:nth-child(3) {
animation-delay: 6s;
}

<div class="fadein">
<img src="http://via.placeholder.com/350x150" style="width:100%">
<img src="http://lorempixel.com/output/animals-q-c-350-150-1.jpg" style="width:100%">
<img src="http://lorempixel.com/output/technics-q-c-350-150-2.jpg" style="width:100%">
</div>
&#13;
Link我的小提琴
答案 0 :(得分:1)
您需要做的就是将position
的{{1}}从img
更改为relative
:
absolute
答案 1 :(得分:0)
如果您还要填充容器,请在position:absolute
之后(提及Niles Tanner)height
和width
值添加100%
。 (顺便说一下,你不需要z-index
财产)
.fadein img
{
max-width: 100%;
max-height:100%;
height:100%;
width:100%;
z-index: -1;
position:absolute;
...
如果您确定自己的照片尺寸相同,请更改.fadein
div的尺寸以保持比例。
.fadein
{
position:absolute;
height:150px;
width:350px;
...