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 controls
function plusSlides(n) {
  showSlides(slideIndex += n);
}

// Thumbnail image controls
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";
}
.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: 0 3px 3px 0;
}

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

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

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

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

.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;
}

.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: 30px 25px;
  overflow: hidden;
  background-color: #F7B233;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  border-radius: 15px;
  font: arial;
}

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

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

li a:hover {
  opacity: 0.6
}

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

.header {
  position: left;
  width: 150px;
  height: 70px;
}
<nav>
  <ul>
    <li><img src="https://picsum.photos/200/300?image=0" class="header"></li>
    <li><a href="#">HOME</a></li>
    <li><a href="#">MENUKAART</a></li>
    <li><a href="#">UIT EIGEN KEUKEN</a></li>
    <li><a href="#">FEESTJES</a></li>
    <li><a href="#">CONTACT</a></li>
    <li><img src="https://picsum.photos/200/300?image=12" class="header"></li>
  </ul>
</nav>

<div class="slideshow-container">

  <div class="mySlides fade">
    <div class="numbertext">1 / 7</div>
    <img src="https://picsum.photos/200/300?image=3" width="825px" height="550px" class="slidehowfoto">
    <div class="text1">text</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">2 / 7</div>
    <img src="https://picsum.photos/200/300?image=7" width="825px" height="550px" class="slidehowfoto">
    <div class="text1">text</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">3 / 7</div>
    <img src="https://picsum.photos/200/300?image=9" width="825px" height="550px" class="slidehowfoto">
    <div class="text1">text</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">4 / 7</div>
    <img src="https://picsum.photos/200/300?image=4" width="825px" height="550px" class="slidehowfoto">
    <div class="text1">text</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">5 / 7</div>
    <img src="https://picsum.photos/200/300?image=11" width="825px" height="550px" class="slidehowfoto">
    <div class="text1">text</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">6 / 7</div>
    <img src="https://picsum.photos/200/300?image=1" width="825px" height="550px" class="slidehowfoto">
    <div class="text1">text</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">7 / 7</div>
    <img src="https://picsum.photos/200/300?image=5" width="825px" height="550px" class="slidehowfoto">
    <div class="text1">text</div>
  </div>

  <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
  <a class="next" onclick="plusSlides(1)">&#10095;</a>
</div>

<br>

<div style="text-align:center">
  <span class="dot" onclick="currentSlide(1)"></span>
  <span class="dot" onclick="currentSlide(2)"></span>
  <span class="dot" onclick="currentSlide(3)"></span>
  <span class="dot" onclick="currentSlide(4)"></span>
  <span class="dot" onclick="currentSlide(5)"></span>
  <span class="dot" onclick="currentSlide(6)"></span>
  <span class="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"