如何在“ slideShow”中一行显示几个DIV?

时间:2018-09-08 18:41:17

标签: javascript html css

我正在尝试使用flexbox来构建我的网站,但幻灯片显示出现问题。

实际上,我正在尝试通过幻灯片在一行中显示2个DIV(图片一个div,图例和文本一个div)

我不知道为什么我的代码无法在一行中显示。你能帮助我吗 ?

非常感谢您

var slideIndex = 0;
showSlides();

function showSlides() {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    var dots = document.getElementsByClassName("dot");
    for (i = 0; i < slides.length; i++) {
       slides[i].style.display = "none";  
    }
    slideIndex++;
    if (slideIndex > slides.length) {slideIndex = 1}    
    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";
    setTimeout(showSlides, 5000); // Change image every 2 seconds
}
@charset "UTF-8";
/* CSS Document */
body {
  margin: 0;
  font-size: 28px;
  background-color: #00011f;
  display: flex;
  flex-direction: column;
  margin : auto;
}



.mySlides {
  display: flex;
}
img {vertical-align: middle;}

/* Slideshow container */


.slideshow-container {
  max-width: 1000px;
  position: relative;
  margin: auto;

}


/* Caption text */
.text {
  color: #f2f2f2;
  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 {
  height: 5px;
  width: 5px;
  margin: 0 2px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
  transition: background-color 0.6s ease;
}

.active {
  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}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
  .text {font-size: 11px}
}
<!DOCTYPE html>
<html>

	<link rel="stylesheet" href="CSS/style2.css" />
	<link rel="shortcut icon" href="IMAGES/PNG/favicon.png" />

    <head>
        <meta charset="utf-8" />
        <title>Electrophotonique Ingenierie</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

    </head>


    <body>
    	
		<div class="slideshow-container">

		<div class="mySlides fade">
		  <img src="IMAGES/PNG/background.png" style="width:100%">
		  <div class="text"> testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest </div>
		</div>

		<div class="mySlides fade">
		  <img src="IMAGES/PNG/eau59h.png" style="width:100%">
		  <div class="text"></div>
		</div>

		<div class="mySlides fade">
		  <img src="IMAGES/PNG/pont.png" style="width:100%">
		  <div class="text"></div>
		</div>

		</div>
		<br>

		<div style="text-align:center">
		  <span class="dot"></span> 
		  <span class="dot"></span> 
		  <span class="dot"></span> 
		</div>




		<div class="content" >test

		</div>


<script type="text/javascript" src="JS/showSlides.js"></script>




</body>
</html>

0 个答案:

没有答案