Skip to content Skip to sidebar Skip to footer

Z-index 'breaks' Slideshow Click Buttons

I've got this problem where my navbar goes behind my slideshow when scrolling. I've had the idea to fix this: adding in the css file the 'z-index: -10;'line. It does works, the na

Solution 1:

You don't need to add z-index here. Keep your navbar codes inside <nav></nav> and everything will be as you expected. Below is the working code:

var slideIndex = 1;
showSlides(slideIndex);

// Next/previous controlsfunctionplusSlides(n) {
  showSlides(slideIndex += n);
}

// Thumbnail image controlsfunctioncurrentSlide(n) {
  showSlides(slideIndex = n);
}

functionshowSlides(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";
}
.slideshow-container {
  width: 825px;
  position: relative;
  margin: auto;
  height: 550px;
  margin-top: 20px;
}

.mySlides {
  display: none;
}

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: white;
  font-weight: bold;
  font-size: 18px;
  transition: 0.6s ease;
  border-radius: 03px3px0;
}

.next {
  right: 0;
  border-radius: 3px003px;
}

.prev:hover,
.next:hover {
  background-color: rgba(0, 0, 0, 0.8);
}

.text1 {
  color: white;
  font-size: 20px;
  padding: 8px12px;
  position: absolute;
  bottom: 12px;
  width: calc(100% - 24px);
  text-align: center;
  font-weight: bold;
  background: #F5A105
}

.numbertext {
  color: #F5A105;
  font-size: 17px;
  padding: 8px12px;
  position: absolute;
  top: 0;
  font-weight: bold;
}

.dot {
  cursor: pointer;
  height: 15px;
  width: 15px;
  margin: 02px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active,
.dot:hover {
  background-color: #717171;
}

/* Fading animation */.fade {
  -webkit-animation-name: fade;
  -webkit-animation-duration: 1.5s;
  animation-name: fade;
  animation-duration: 1.5s;
}

@-webkit-keyframes fade {
  from {
    opacity: .4
  }
  to {
    opacity: 1
  }
}

@keyframes fade {
  from {
    opacity: .4
  }
  to {
    opacity: 1
  }
}

.slidehowfoto {
  border-radius: 15px;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 30px25px;
  overflow: hidden;
  background-color: #F7B233;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  border-radius: 15px;
  font: arial;
}

li {
  float: left;
  text-decoration-color: black;
}

lia {
  display: block;
  background-color: #F7B233;
  color: white;
  text-align: center;
  padding: 25px15px;
  text-decoration: burlywood;
  font-weight: bold;
  opacity: 1;
  transition: 0.3s;
  outline: none;
  border-radius: 15px;
  box-shadow: 07px white;
}

lia:hover {
  opacity: 0.6
}

a {
  border-right: 5px white;
  border-radius: 5px;
}

.header {
  position: left;
  width: 150px;
  height: 70px;
}
<nav><ul><li><imgsrc="https://picsum.photos/200/300?image=0"class="header"></li><li><ahref="#">HOME</a></li><li><ahref="#">MENUKAART</a></li><li><ahref="#">UIT EIGEN KEUKEN</a></li><li><ahref="#">FEESTJES</a></li><li><ahref="#">CONTACT</a></li><li><imgsrc="https://picsum.photos/200/300?image=12"class="header"></li></ul></nav><divclass="slideshow-container"><divclass="mySlides fade"><divclass="numbertext">1 / 7</div><imgsrc="https://picsum.photos/200/300?image=3"width="825px"height="550px"class="slidehowfoto"><divclass="text1">text</div></div><divclass="mySlides fade"><divclass="numbertext">2 / 7</div><imgsrc="https://picsum.photos/200/300?image=7"width="825px"height="550px"class="slidehowfoto"><divclass="text1">text</div></div><divclass="mySlides fade"><divclass="numbertext">3 / 7</div><imgsrc="https://picsum.photos/200/300?image=9"width="825px"height="550px"class="slidehowfoto"><divclass="text1">text</div></div><divclass="mySlides fade"><divclass="numbertext">4 / 7</div><imgsrc="https://picsum.photos/200/300?image=4"width="825px"height="550px"class="slidehowfoto"><divclass="text1">text</div></div><divclass="mySlides fade"><divclass="numbertext">5 / 7</div><imgsrc="https://picsum.photos/200/300?image=11"width="825px"height="550px"class="slidehowfoto"><divclass="text1">text</div></div><divclass="mySlides fade"><divclass="numbertext">6 / 7</div><imgsrc="https://picsum.photos/200/300?image=1"width="825px"height="550px"class="slidehowfoto"><divclass="text1">text</div></div><divclass="mySlides fade"><divclass="numbertext">7 / 7</div><imgsrc="https://picsum.photos/200/300?image=5"width="825px"height="550px"class="slidehowfoto"><divclass="text1">text</div></div><aclass="prev"onclick="plusSlides(-1)">&#10094;</a><aclass="next"onclick="plusSlides(1)">&#10095;</a></div><br><divstyle="text-align:center"><spanclass="dot"onclick="currentSlide(1)"></span><spanclass="dot"onclick="currentSlide(2)"></span><spanclass="dot"onclick="currentSlide(3)"></span><spanclass="dot"onclick="currentSlide(4)"></span><spanclass="dot"onclick="currentSlide(5)"></span><spanclass="dot"onclick="currentSlide(6)"></span><spanclass="dot"onclick="currentSlide(7)"></span></div>

And Here's the JSFiddle: http://jsfiddle.net/epots2bu/15/

Post a Comment for "Z-index 'breaks' Slideshow Click Buttons"