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?). I'he already tried everything: borders, margins, paddings, outlines in a different park of code (images, divs, bootstrap.css) - nothing helps. 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. While you could overwrite this, it would make more sense to simply remove the class from your main .container <div> element.
Also, note that <div> elements are 100% with by default, so you don't actually need this outer <div> container at all; you can simply start your carousel with <div id="myCarousel">, as is shown in the following example:
<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! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With