How to make Bootstrap 4 carousel images responsive?

NiZa picture NiZa · Feb 22, 2017 · Viewed 26.5k times · Source

Hopfully the title and the demo say it all. The new carousel of Bootstrap 4 isn't responsive. The images are out of their aspect ratio.

Does somebody know how to solve this without doing major adjustments in the css and html?

.wrapper {
  max-width:200px;
  width:100%;
}
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="wrapper">
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner" role="listbox">
    <div class="carousel-item active">
      <img class="d-block img-fluid" src="https://placehold.it/400x200" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block img-fluid" src="https://placehold.it/400x200" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block img-fluid" src="https://placehold.it/400x200" alt="Third slide">
    </div>
  </div>
</div>
</div>

Answer

user6926558 picture user6926558 · Feb 22, 2017

You do not need a wrapper or something like that. The default styling for the .active .carousel-item is display: flex.

You will need to add

.carousel-item.active,
.carousel-item-next,
.carousel-item-prev {
  display: block;
}

to your custom css.