I'm struggling to maintain a consistent height of 700px for my image slideshow, which consists of four images with varying heights. I attempted setting the img
at max-height: 700px
, but unfortunately that didn't yield the desired outcome.
You can view the codepen here.
var slideIndex = 1;
showSlide(slideIndex);
function plusSlides(n) {
showSlide(slideIndex += n);
}
function currentSlide(n) {
showSlide(slideIndex = n);
}
function showSlide(n) {
var i;
var slides = document.getElementsByClassName("myslides");
var dots = document.getElementsByClassName("dots");
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";
}
body{
font-family: verdana,sans-serif;
margin: 0;
font-size: 100%;
}
#slideshow-container{
position: relative;
margin: auto;
background-color: black;
overflow: hidden;
}
#slideshow-container img{
display: block;
margin: 0 auto;
max-width: 100%;
position: relative;
max-height: 700px !important;
}
.myslides{
display: none;
}
.prev , .next{
position: absolute;
top: 50%;
font-size: 30px;
font-weight: bold;
padding: 16px;
margin-top: -22px;
border-radius: 0 3px 3px 0;
color: #fff;
cursor: pointer;
z-index: 1;
}
.next{
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover,.next:hover{
background-color: rgba(0,0,0,0.8);
}
.caption{
text-align: center;
position: absolute;
bottom: 5px;
width: 100%;
color: #f2f2f2;
font-size: 1em;
/* font-size:15px ; */
/* padding:8px 22px ; */
}
.fade{
animation-name:fade ;
animation-duration:1.5s ;
}
@keyframes fade{
from {opacity: 0.4;}
to {opacity: 1 ;}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!---Images not owned by me --->
<div id="slideshow-container">
<div id="mainImg">
<div class="myslides fade">
<div><img src="https://static.boredpanda.com/blog/wp-content/uploads/2014/12/Top-10-photographers-for-travel-portraits27__700.jpg"></div>
<div class="caption">Text 1</div>
</div>
<div class="myslides fade">
<div><img src="https://cdn-images-1.medium.com/max/1600/1*way-yv9effv2b7PKZeUDMA.png"></div>
<div class="caption">Text 2</div>
</div>
<div class="myslides fade">
<div><img src="https://www.shutterbug.com/images/17/promosa111217.png"></div>
<div class="caption">Text 3</div>
</div>
<div class="myslides fade">
<div><img src="http://jmacpratt.weebly.com/uploads/1/2/0/1/12013129/portrait2_orig.jpg"></div>
<div class="caption">Text 4</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>