I have the following pure css slideshow and I'm trying to implement "next/prev" buttons in addition to the thumbnails (both are labels pointing to a <input type="radio">
).
The thumbnails are labels with an image inside, so I created more labels for the buttons. The problem is that I can't figure out how to correctly hide them all except for the ones next to the checked input.
I've tried the following code:
.slider input[name='slide_switch'] ~ label.next,
.slider input[name='slide_switch'] ~ label.previous
{
z-index: -1
}
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1
}
That should target all <label class="next">
and <label class="previous">
in the HTML, but for some reason it's not working, I "can see" more than one button,one upon another, because I gave them opacity: 0.6
and they don't look semi-transparent. However the last two of them show the correct opacity and are working, if I'm in the last picture I can click the previous button and it'll take me to the 4th picture, and if I click next it takes me to the 5th (unfortunately this happens with all pictures).
I'm working it here: https://jsfiddle.net/5v6ajfup/
The HTML code:
<div class="slider">
<input type="radio" name="slide_switch" id="id1"/>
<label class="thumbnail" for="id1">
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/3yiC6Yq.jpg"/>
<label class="next" for="id2">></label>
<input type="radio" name="slide_switch" id="id2" checked="checked"/>
<label class="thumbnail" for="id2">
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/40Ly3VB.jpg"/>
<label class="previous" for="id1">></label>
<label class="next" for="id3">></label>
<input type="radio" name="slide_switch" id="id3"/>
<label class="thumbnail" for="id3">
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/00kih8g.jpg"/>
<label class="previous" for="id2">></label>
<label class="next" for="id4">></label>
<input type="radio" name="slide_switch" id="id4"/>
<label class="thumbnail" for="id4">
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/2rT2vdx.jpg"/>
<label class="next" for="id5">></label>
<label class="previous" for="id3">></label>
<input type="radio" name="slide_switch" id="id5"/>
<label class="thumbnail" for="id5">
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg" width="100"/>
</label>
<img src="http://thecodeplayer.com/uploads/media/8k3N3EL.jpg"/>
<label class="previous" for="id4">></label>
</div>
The CSS code:
* { margin: 0; padding: 0 }
body { background: #ccc }
.slider {
width: 640px;
position: relative;
padding-top: 320px;
margin: 20px auto;
box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.75);
}
.slider > img {
position: absolute;
left: 0; top: 0;
transition: all 0.5s;
display: block
}
.slider input[name='slide_switch'] {
display: none;
}
.slider label.next, .slider label.previous {
position: absolute;
left: 0; top: 0;
display: block;
font-size:3em;
opacity: 0.6;
cursor: pointer;
color: white;
}
.slider label.next { left: 560px; line-height: 320px }
.slider label.previous { left: 50px; line-height: 320px; transform: rotateY(180deg) }
.slider label.thumbnail {
margin: 18px 0 0 18px;
border: 3px solid #999;
float: left;
cursor: pointer;
transition: all 0.5s;
opacity: 0.6;
}
.slider label.thumbnail:hover { opacity: 0.8 }
.slider label.thumbnail img {
display: block;
}
.slider input[name='slide_switch']:checked + label.thumbnail {
border-color: #666;
opacity: 1;
}
.slider input[name='slide_switch'] ~ label.next,
.slider input[name='slide_switch'] ~ label.previous
{
z-index: -1
}
.slider input[name='slide_switch']:checked ~ label.next,
.slider input[name='slide_switch']:checked ~ label.previous {
z-index: 1
}
.slider input[name='slide_switch'] ~ img {
opacity: 0;
transform: scale(1.1);
}
.slider input[name='slide_switch']:checked + label.thumbnail + img {
opacity: 1;
transform: scale(1);
}
(Source)