简体   繁体   English

如何删除 Bootstrap Carousel 中的空格?

[英]How to remove whitespaces in Bootstrap Carousel?

I have a problem with Bootstrap Carousel - I want it to be 100% width, from edge to edge, but I can't get rid of small whitespaces on the left and right (margins?).我对 Bootstrap Carousel 有问题 - 我希望它从边缘到边缘的宽度为 100%,但我无法摆脱左右两侧的小空格(边距?)。 I'he already tried everything: borders, margins, paddings, outlines in a different park of code (images, divs, bootstrap.css) - nothing helps.我已经尝试了一切:边框、边距、填充、不同代码公园中的轮廓(图像、div、bootstrap.css) - 没有任何帮助。 Any clues?有什么线索吗? Here's what I'm talking about.这就是我要说的。

Here is part of my code:这是我的代码的一部分:

<div class="container" style="width: 100%;">
  <div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="3000" style="">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
      <li data-target="#myCarousel" data-slide-to="3"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox" style="margin: 0px; padding: 0px; border: 0px; margin: none; ">
      <div class="item active">
        <img src="img/back_1.JPG" alt="Chania" style="min-width:100%; margin: none; padding: none;">
      </div>

      <div class="item">
        <img src="img/back_2.jpg" alt="Chania" style="width:100%;">
      </div>

      <div class="item">
        <img src="img/back_3.jpg" alt="Flower" style="width:100%;" >
      </div>

      <div class="item">
        <img src="img/back_4.jpg" alt="Flower" style="width:100%;">
      </div>
    </div>
  </div>
</div>

The white space on either side of your carousel is coming from the container class, which adds padding-left: 15px and padding-right: 15px .旋转木马两侧的空白区域来自container类,它添加了padding-left: 15pxpadding-right: 15px While you could overwrite this, it would make more sense to simply remove the class from your main .container <div> element.虽然您可以覆盖它,但从您的主要.container <div>元素中简单地删除类会更有意义。

Also, note that <div> elements are 100% with by default, so you don't actually need this outer <div> container at all ;另外,还要注意<div>元素是100%在默认情况下,所以你实际上并不需要这种外部<div>容器中,在所有; you can simply start your carousel with <div id="myCarousel"> , as is shown in the following example:您可以简单地使用<div id="myCarousel">启动轮播,如下例所示:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="3000" style=""> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> <li data-target="#myCarousel" data-slide-to="3"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner" role="listbox" style="margin: 0px; padding: 0px; border: 0px; margin: none; "> <div class="item active"> <img src="http://placehold.it/100" alt="Chania" style="min-width:100%; margin: none; padding: none;"> </div> <div class="item"> <img src="http://placehold.it/100" alt="Chania" style="width:100%;"> </div> <div class="item"> <img src="http://placehold.it/100" alt="Flower" style="width:100%;"> </div> <div class="item"> <img src="http://placehold.it/100" alt="Flower" style="width:100%;"> </div> </div> </div>

Hope this helps!希望这可以帮助! :) :)

same problem here but the code solution above didn't work for me... When i removed the column (using bootstrap 4.4) my small images didn't got fullscreen when i maximized my window.这里有同样的问题,但上面的代码解决方案对我不起作用......当我删除列(使用引导程序 4.4)时,当我最大化窗口时,我的小图像没有全屏显示。 The solution was here to add a css class i called .nomargin with margin and padding set to 0. I added this class right after col-12 class.解决方案是在这里添加一个名为 .nomargin 的 css 类,边距和填充设置为 0。我在 col-12 类之后添加了这个类。 So my code looks like this:所以我的代码看起来像这样:

 <!-- Header Carousel --> <header class="container-fluid"> <div class="row"> <div class="col-12 nomargin"> <div id="carouselExampleControls" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img src="img/pictures/_MG_9515_web.jpg" class="d-block w-100" alt="..."> </div> <div class="carousel-item"> <img src="img/pictures/_MG_9629_web.jpg" class="d-block w-100" alt="..."> </div> <div class="carousel-item"> <iframe class="embed-responsive" src="https://www.kijkrond.in/stationroeselare/" alt="..." > </iframe> </div> </div> <a class="carousel-control-prev" href="#carouselExampleControls" 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="#carouselExampleControls" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div> </div> </header>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM