My CSS, HTML, and JavaScript slide show is not working correctly

I am using a slideshow template that was supposed to be for three slides, styled with a little css, but when i went to add more slides, it completely removed the navigation buttons.

here is my code:

<div class="slideshow-container">
  <div class="mySlides fade">
    <div class="numbertext">1 / 9</div>
		<img src="images/tour/bedroom_1.jpg">
    <div class="text">The Bedrooms</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">2 / 9</div>
    <img src="images/tour/bedroom_2.jpg">
    <div class="text">The Bedrooms</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">3 / 9</div>
    <img src="images/tour/bedroom_9.jpg">
    <div class="text">The Bedrooms</div>
	<div class="slideshow-container">
	
  <div class="mySlides fade">
    <div class="numbertext">4 / 9</div>
		<img src="images/tour/dining_1.jpg">
    <div class="text">Fine Dining</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">5 / 9</div>
    <img src="images/tour/dining_2.jpg">
    <div class="text">Fine Dining</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">6 / 9</div>
    <img src="images/tour/dining_9.jpg">
    <div class="text">Fine Dining</div>
  </div>
  
    <div class="mySlides fade">
    <div class="numbertext">7 / 9</div>
		<img src="images/tour/Lobby_1.jpg">
    <div class="text">The Lobby</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">8 / 9</div>
    <img src="images/tour/lobby_2.jpg">
    <div class="text">The Lobby</div>
  </div>

  <div class="mySlides fade">
    <div class="numbertext">9 / 9</div>
    <img src="images/tour/lobby_9.jpg">
    <div class="text">The lobby</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>
  <span class="dot" onclick="currentSlide(8)"></span>
  <span class="dot" onclick="currentSlide(9)"></span>
</div>
<script>
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";
}
</script>

</div>

The CSS:

* {box-sizing:border-box}

/* Slideshow container */
.slideshow-container {
  max-width: 950px;
  position: relative;
  margin: auto;
}

.mySlides {
    display: none;
}

/* Next & previous buttons */
.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;
}

/* Position the "next button" to the right */
.next {
  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);
}

/* Caption text */
.text {
  color: white;
  font-size: 15px;
  padding: 8px 12px;
  position: absolute;
  bottom: 8px;
  width: 100%;
  text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
  color: #f2f2f2;
  font-size: 12px;
  padding: 8px 12px;
  position: absolute;
  top: 0;
}

/* The dots/bullets/indicators */
.dot {
  cursor:pointer;
  height: 13px;
  width: 13px;
  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}
}

Have you validated your HTML?
https://validator.w3.org/nu/

In the third group above, the last line looks out of place.

            <div class="slideshow-container">

It should be replaced by a close </div>.

Other than that, it would be nice if the URLs to the images worked. :slight_smile:

May I ask who publishes the slider?

1 Like

I got the slideshow code from https://www.w3schools.com/howto/howto_js_slideshow.asp
Ill try validating it, and replacing the code you pointed out and ill get back to you

that code error you pointed out did turn out to be the problem.

4 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.