使用 CSS 停止背景重复

问题描述 投票:0回答:1

我在背景中设置了

<li>
,并添加了关键帧来循环浏览图像。我的目标是使用这些来创建精益循环动画,但我无法阻止背景图像重复。

有一张图像我无法控制,而下面的一张图像的大小和位置正确。

如有任何帮助,我们将不胜感激。

.cb-slideshow span { 
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  color: transparent;
  background-size:cover;
  background-position: 50% 50%;
  opacity: 0;
  z-index: 0;
  animation: imageAnimation 8s linear infinite 0s;
  background-repeat: no-repeat;
}

.cb-slideshow li:nth-child(1) span { 
  background-image: url(../images/1.jpg) 
}
.cb-slideshow li:nth-child(2) span { 
  background-image: url(../images/2.jpg);
  animation-delay: 1s; 
}
.cb-slideshow li:nth-child(3) span { 
  background-image: url(../images/3.jpg);
  animation-delay: 2s; 
}
.cb-slideshow li:nth-child(4) span { 
  background-image: url(../images/4.jpg);
  animation-delay: 3s; 
}
.cb-slideshow li:nth-child(5) span { 
  background-image: url(../images/5.jpg);
  animation-delay: 4s; 
}
.cb-slideshow li:nth-child(6) span { 
  background-image: url(../images/6.jpg);
  animation-delay: 5s; 
}
.cb-slideshow li:nth-child(7) span { 
  background-image: url(../images/7.jpg);
  animation-delay: 6s; 
}
.cb-slideshow li:nth-child(8) span { 
  background-image: url(../images/8.jpg);
  animation-delay: 7s; 
}

@keyframes imageAnimation { 
  0% { opacity: 0 }
  0.1% { opacity: 1 } 
  12.5% { opacity: 1 }
  12.6% { opacity: 0 }
  100% { opacity: 0 }
}

.no-cssanimations .cb-slideshow li span{
  opacity: 1;
}
<ul class="cb-slideshow">
    <li>
        <span><img src="Images/1.jpg" ></span>
    </li>
    <li>
        <span><img src="Images/2.jpg" ></span>
    </li>
    <li>
        <span><img src="Images/3.jpg" ></span>
    </li>
    <li>
        <span><img src="Images/4.jpg" ></span>
    </li>
    <li>
        <span><img src="Images/5.jpg" ></span>
    </li>
    <li>
        <span><img src="Images/6.jpg" ></span>
    </li>
    <li>
        <span><img src="Images/7.jpg" ></span>
    </li>
    <li>
        <span><img src="Images/8.jpg" ></span>
    </li>                                  
</ul>

html css background-image css-animations
1个回答
1
投票

您可以使用CSS属性

background-repeat: no-repeat;
来防止图像重复。

© www.soinside.com 2019 - 2024. All rights reserved.