My goal is to build a CSS-only automatic animated slider with navigation buttons. While the slider animation and navigation function separately, combining them causes the automatic animation to override the navigation system, preventing me from switching between slides using the buttons. How can I ensure that the animation does not overpower the navigation so that I can navigate between slides while maintaining the automatic scrolling feature? Below is my code:
.slider {
width: 100%;
height: 300px;
overflow: hidden;
}
figure p {
position: absolute;
}
figure {
position: relative;
width: 400%;
margin: 0;
left: 0;
text-align: center;
transition: left 2s;
animation: 20s slidy infinite;
}
.slider figure .slide {
width: 25%;
float: left;
}
.slider figure img {
width: 100%;
height: 300px;
}
.button_container {
position: relative;
top: -30px;
text-align: center;
}
.slider_button {
display: inline-block;
height: 15px;
width: 15px;
border-radius: 50%;
background-color: black;
margin: 0px 15px;
}
#slide-1:target~.slide_container {
left: 0%;
}
#slide-2:target~.slide_container {
left: -100%;
}
#slide-3:target~.slide_container {
left: -200%;
}
#slide-4:target~.slide_container {
left: -300%;
}
@keyframes slidy {
0% {
left: 0%;
}
21% {
left: 0%;
}
25% {
left: -100%;
}
46% {
left: -100%;
}
50% {
left: -200%;
}
71% {
left: -200%;
}
75% {
left: -300%;
}
96% {
left: -300%;
}
100% {
left: 0%;
}
}
<div class="slider">
<span id="slide-1"></span>
<span id="slide-2"></span>
<span id="slide-3"></span>
<span id="slide-4"></span>
<figure class="slide_container">
<div class="slide">
<p>Test1</p>
<img src="https://via.placeholder.com/300?text=1" class="slider_image">
</div>
<div class="slide">
<p>Test2</p>
<img src="https://via.placeholder.com/300?text=2" class="slider_image">
</div>
<div class="slide">
<p>Test3</p>
<img src="https://via.placeholder.com/300?text=3" class="slider_image">
</div>
<div class="slide">
<p>Test4</p>
<img src="https://via.placeholder.com/300?text=4" class="slider_image">
</div>
</figure>
<div class="button_container">
<a href="#slide-1" class="slider_button"></a>
<a href="#slide-2" class="slider_button"></a>
<a href="#slide-3" class="slider_button"></a>
<a href="#slide-4" class="slider_button"></a>
</div>
</div>