简体   繁体   English

CSS褪色图片库

[英]CSS fading picture gallery

I'm trying to make a multiple images gallery that switches and fades In and Out the pictures automatically. 我正在尝试制作一个可以自动切换和淡入和淡出图片的多重图像库。 I'm trying to do it with CSS only, but it doesn't work. 我正在尝试仅使用CSS来执行此操作,但是它不起作用。

Here is the HTML 这是HTML

<div id="cf4a">
  <img src="img/1a.jpg"/>   
  <img src="img/2a.jpg"/>
  <img src="img/3a.jpg" />
  <img src="img/4a.jpg"/>
</div>

And here is the CSS 这是CSS

@keyframes cf4aFadeInOut {
  0% {
    opacity:1;
  }
  17% {
    opacity:1;
  }
  25% {
    opacity:0;
  }
  92% {
    opacity:0;
  }
  100% {
    opacity:1;
  }
}

#cf4a {
  position:relative;
  top:200px;
  right:0;
  left:0;
  bottom:0;
  background:red;
  height:280px;
  width:100%;
  margin:auto;
}

#cf4a img {
  position:absolute;
  width:100%;
  height:280px;
  left:0;
  animation-name: cf4aFadeInOut;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-duration: 2s;
  animation-direction: alternate;
}

#cf4a img:nth-of-type(1) {
  animation-delay: 6s;
}
#cf4a img:nth-of-type(2) {
  animation-delay: 4s;
}
#cf4a img:nth-of-type(3) {
  animation-delay: 2s;
}
#cf4a img:nth-of-type(4) {
  animation-delay: 0;
}

It won't switch! 它不会切换! I'm pretty new to HTML & CSS, so I used this guide: http://css3.bradshawenterprises.com/cfimg/ 我对HTML和CSS相当陌生,因此我使用了本指南: http : //css3.bradshawenterprises.com/cfimg/

Thanks in advance :) 提前致谢 :)

PS i know you can do this with jQuery, but I'd rather use CSS. PS我知道你可以用jQuery做到这一点,但我宁愿使用CSS。

@keyframes cf4FadeInOut class name is wrong according to your code. 根据您的代码,@ keyframes cf4FadeInOut类名称错误。

Should be "@keyframes cf4aFadeInOut" instead ?? 应该是“ @keyframes cf4aFadeInOut”而不是?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM