我想实现一个纯CSS滑块,它包含以下组件: -
我将这些模块用2个单独的代码实现,但是当我将它们组合在一起时,只显示第一个图像,然后剩下的图像变得不可见。我无法弄清楚出了什么问题。
这是HTML代码:
<body>
<ul class="slides">
<input type="radio" name="radio-btn" id="img-1" checked />
<li class="slide-container">
<div class="slide">
<img class="image" src="img/1.jpg" />
</div>
<div class="nav">
<label for="img-4" class="prev">‹</label>
<label for="img-2" class="next">›</label>
</div>
</li>
<input type="radio" name="radio-btn" id="img-2" />
<li class="slide-container">
<div class="slide">
<img class="image" src="img/2.jpg" />
</div>
<div class="nav">
<label for="img-1" class="prev">‹</label>
<label for="img-3" class="next">›</label>
</div>
</li>
<input type="radio" name="radio-btn" id="img-3" />
<li class="slide-container">
<div class="slide">
<img class="image" src="img/3.jpg" />
</div>
<div class="nav">
<label for="img-2" class="prev">‹</label>
<label for="img-4" class="next">›</label>
</div>
</li>
<input type="radio" name="radio-btn" id="img-4" />
<li class="slide-container">
<div class="slide">
<img class="image" src="img/4.jpg" />
</div>
<div class="nav">
<label for="img-3" class="prev">‹</label>
<label for="img-1" class="next">›</label>
</div>
</li>
<li class="nav-dots">
<label for="img-1" class="nav-dot" id="img-dot-1"></label>
<label for="img-2" class="nav-dot" id="img-dot-2"></label>
<label for="img-3" class="nav-dot" id="img-dot-3"></label>
<label for="img-4" class="nav-dot" id="img-dot-4"></label>
</li>
</ul>
</body>
这是我到目前为止所做的相应CSS代码:
.slides {
padding: 0;
width: 1100px;
height: 550px;
display: block;
margin: 0 auto;
position: relative;
}
.slides * {
user-select: none;
-ms-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-webkit-touch-callout: none;
}
.slides input { display: none; }
.slide-container { display: block; }
.slide {
top: 0;
opacity: 0;
width: 1100px;
height: 550px;
display: block;
position: absolute;
}
.slide img {
width: 100%;
height: 100%;
}
.nav label {
width: 150px;
height: 100%;
display: none;
position: absolute;
opacity: 0;
z-index: 9;
cursor: pointer;
transition: opacity .2s;
color: #FFF;
font-size: 156pt;
text-align: center;
line-height: 380px;
font-family: "Varela Round", sans-serif;
background-color: rgba(255, 255, 255, .3);
text-shadow: 0px 0px 15px rgb(119, 119, 119);
}
.slide:hover + .nav label { opacity: 0.35; }
.nav label:hover { opacity: 1; }
.nav .next { right: 0; }
input:checked + .slide-container .slide {
opacity: 1;
transition: opacity 1s ease-in-out;
}
input:checked + .slide-container .nav label { display: block; }
.nav-dots {
width: 100%;
bottom: 9px;
height: 11px;
display: block;
position: absolute;
text-align: center;
}
.nav-dots .nav-dot {
top: -5px;
width: 11px;
height: 11px;
margin: 0 4px;
position: relative;
border-radius: 100%;
display: inline-block;
background-color: rgba(0, 0, 0, 0.6);
}
.nav-dots .nav-dot:hover {
cursor: pointer;
background-color: rgba(0, 0, 0, 0.8);
}
input#img-1:checked ~ .nav-dots label#img-dot-1,
input#img-2:checked ~ .nav-dots label#img-dot-2,
input#img-3:checked ~ .nav-dots label#img-dot-3,
input#img-4:checked ~ .nav-dots label#img-dot-4{
background: rgba(0, 0, 0, 0.8);
}
.slide, .nav-dot {
opacity:0;
/* css3 animation */
-webkit-animation-name: anim_slides;
-webkit-animation-duration: 24.0s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: normal;
-webkit-animation-delay: 0s;
-webkit-animation-play-state: running;
-webkit-animation-fill-mode: forwards;
-moz-animation-name: anim_slides;
-moz-animation-duration: 24.0s;
-moz-animation-timing-function: linear;
-moz-animation-iteration-count: infinite;
-moz-animation-direction: normal;
-moz-animation-delay: 0s;
-moz-animation-play-state: running;
-moz-animation-fill-mode: forwards;
}
/* delays */
.slide, .nav-dot:nth-child(2){
-webkit-animation-delay: 6.0s;
-moz-animation-delay: 6.0s;
}
.slide, .nav-dot:nth-child(3){
-webkit-animation-delay: 12.0s;
-moz-animation-delay: 12.0s;
}
.slide, .nav-dot:nth-child(4){
-webkit-animation-delay: 18.0s;
-moz-animation-delay: 18.0s;
}
@-webkit-keyframes anim_slides {
0% {opacity:0;}
10% {opacity:1;}
30% {opacity:1;}
36% {opacity:0;}
100% {opacity:0;}
}
@-moz-keyframes anim_slides {
0% {opacity:0;}
10% {opacity:1;}
30% {opacity:1;}
36% {opacity:0;}
100% {opacity:0;}
}
请告诉我哪里出错了。