在div中归档堆栈的图像

时间:2017-08-25 12:18:13

标签: html css

我无法将我的图像填充到单个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;
&#13;
&#13;

Link我的小提琴

2 个答案:

答案 0 :(得分:1)

您需要做的就是将position的{​​{1}}从img更改为relative

absolute

答案 1 :(得分:0)

如果您还要填充容器,请在position:absolute之后(提及Niles Tannerheightwidth值添加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;
...