I am facing a challenge with my slideshow project. The slideshow consists of images and text on each slide, along with previous and next buttons that are aligned within the parent container. I am trying to align these buttons at the midpoint of each image in the slides while ensuring responsiveness. Here is the code snippet:
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {
slideIndex = 1;
}
if (n < 1) {
slideIndex = slides.length;
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
}
@import url("https://use.typekit.net/yoj6eqg.css");
* {
box-sizing: border-box
}
body {
font-family: Assistant, sans-serif;
margin: 0
}
/* Slideshow container */
.slideshow-container {
position: relative;
background: #f1f1f1f1;
width: 100%;
margin: auto;
}
/* Slides */
.mySlides {
display: none;
padding: 30px 30px 30px 30px;
text-align: center;
width: 62.5%;
margin: auto;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -30px;
padding: 30px;
color: #888;
font-weight: bold;
font-size: 20px;
border-radius: 0 3px 3px 0;
user-select: none;
}
/* Position the "next button" to the right */
.next {
position: absolute;
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
color: white;
}
.image {
background-position: center;
background-repeat: no-repeat;
background-size: cover;
height: 60vh;
}
/* The dot/bullet/indicator container */
.dot-container {
text-align: center;
padding: 20px;
background: #ddd;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
/* Add a background color to the active dot/circle */
.dot:hover {
background-color: #90bd49;
}
.active {
background-color: #90bd49;
}
/* text color */
.text {
color: black;
text-align: left;
}
.heading {
text-align: center;
color: #7bd934;
font-size: 30px;
font-family: Assistant, sans-serif;
padding: 10px;
}
@media screen and (max-width:767px) {
.heading {
font-size: 20px;
}
.text {
font-size: 12px;
}
.prev,
.next {
font-size: 15px;
border-radius: 0 3px 3px 0;
padding: 10px;
}
.mySlides {
display: none;
padding: 30px 50px 30px 50px;
}
}
<div class="slideshow-container">
<div class="mySlides">
<div style="background-image: url('https://wallpaperset.com/w/full/a/c/7/185665.jpg');" class="image"> </div>
<p class="heading">Lorem ipsum</p>
<p class="text">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</p>
</div>
<div class="mySlides">
<div style="background-image: url('https://wallpaperset.com/w/full/a/c/7/185665.jpg');" class="image"> </div>
<p class="heading">Lorem ipsum</p>
<p class="text">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</p>
</div>
<div class="mySlides">
<div style="background-image: url('https://wallpaperset.com/w/full/a/c/7/185665.jpg');" class="image"> </div>
<p class="heading">Lorem ipsum</p>
<p class="text">Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</p>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a> <a class="next" onclick="plusSlides(1)">❯</a></div>
<div class="dot-container">
<div class="dot" onclick="currentSlide(1)"></div>
<div class="dot" onclick="currentSlide(2)"></div>
<div class="dot" onclick="currentSlide(3)"></div>
</div>
You can access the code here.
I have attempted to embed the button div into each slide div without success. I also tried placing it within each background picture div, which did not work either. Although adjusting the top percentage using media queries may seem like a solution, it only addresses the issue at specific breakpoints.
I believe there must be a responsive solution that has eluded me. Any help in achieving this goal would be greatly appreciated.