本文介绍了如何集中一个Photoslideshow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将我的photoslideshow置中。
我希望你们能帮助我。



Html中的Photoslideshow:

 使用 margin:auto; 和 display:block;  style用于中心图像。看到这里显示中心图像。 。



试试以下css风格:

  .w3-content img {
display:block;
margin:0 auto;
}

演示

var myIndex = 0; carousel(); function carousel(){var i; var x = document.getElementsByClassName(mySlides); for(i = 0; i< x.length; i ++){x [i] .style.display =none; } myIndex ++; if(myIndex> x.length){myIndex = 1} x [myIndex - 1] .style.display =block; setTimeout(carousel,2500);}
.w3-content img {display:block; margin:0 auto;}
 < div class = w3-content w3-section> < img class =mySlidessrc =https://placehold.it/100x100> < img class =mySlidessrc =https://placehold.it/150x150> < img class =mySlidessrc =https://placehold.it/200x200>< / div>  


I have trouble with centering my photoslideshow....I hope you guys could help me.

Photoslideshow in Html :

<div class="w3-content w3-section" style="max-width:500px">
    <img class="mySlides" src="4.jpg">
    <img class="mySlides" src="3.jpg">
    <img class="mySlides" src="2.jpg">
</div>

<script>
    var myIndex = 0;
    carousel();

    function carousel() {
        var i;
        var x = document.getElementsByClassName("mySlides");
        for (i = 0; i < x.length; i++) {
            x[i].style.display = "none";
        }
        myIndex++;
        if (myIndex > x.length) { myIndex = 1 }
        x[myIndex - 1].style.display = "block";
        setTimeout(carousel, 2500);
    }
</script>
解决方案

Use margin: auto; and display: block; style For center image. see here for display center image. http://www.w3schools.com/css/css_align.asp.

Try below css style:

 .w3-content img{
      display: block;
      margin:0 auto;
 }

Demo

var myIndex = 0;
carousel();

function carousel() {
  var i;
  var x = document.getElementsByClassName("mySlides");
  for (i = 0; i < x.length; i++) {
    x[i].style.display = "none";
  }
  myIndex++;
  if (myIndex > x.length) {
    myIndex = 1
  }
  x[myIndex - 1].style.display = "block";
  setTimeout(carousel, 2500);
}
.w3-content img{
  display: block;
  margin:0 auto;
}
<div class="w3-content w3-section">
  <img class="mySlides" src="https://placehold.it/100x100">
  <img class="mySlides" src="https://placehold.it/150x150">
  <img class="mySlides" src="https://placehold.it/200x200">
</div>

这篇关于如何集中一个Photoslideshow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 19:00