我的旋转木马进入全屏模式,但我希望它的尺寸​​要小一些,例如在左右两侧都留有页边距,因此它不会占用整个页面。使用CSS进行了尝试,但到目前为止还没有运气。

<section id="slider">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
      <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
      <div class="carousel-item active"> <img class="d-block w-100" src="wildfire1.jpg" alt="waldbrband1"> </div>
      <div class="carousel-item"> <img class="d-block w-100" src="wildfire2.jpg" alt="waldbrand2"> </div>
      <div class="carousel-item"> <img class="d-block w-100" src="wildfire3.jpg" alt="waldbrand3"> </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a>
    <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a>
  </div>
</section>

最佳答案

我不确定这是否是最好的方法,但是您可以将代码放在这样的容器中:

<div class="MySlider-container">
<section id="slider">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
      <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
      <div class="carousel-item active"> <img class="d-block w-100" src="wildfire1.jpg" alt="waldbrband1"> </div>
      <div class="carousel-item"> <img class="d-block w-100" src="wildfire2.jpg" alt="waldbrand2"> </div>
      <div class="carousel-item"> <img class="d-block w-100" src="wildfire3.jpg" alt="waldbrand3"> </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleIndicators"
      role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a>
  </div>
</section>
</div>


而且您的CSS代码看起来像这样:

.MySlider-container {
  margin-left: 5rem;
  margin-right: 5rem;
}

关于javascript - 如何缩小旋转木马幻灯片的显示?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54831791/

10-10 22:01