I have a bootstrap carousel that contains images of different sizes, so when the carousel slides, the carousel changes it's dimensions to fit with the size of the image.
When i user w-100 or h-100 on the images, it still changes the carousel width or height depending on the overflow of the image on the carousel borders.
How do i stop this from happening, so that the carousel has a fixed height and width within its "col-8" parent. Below is my HTML for reference, there is no extra CSS on this page that isn't bootstrap. Thanks.
<div id="carouselExampleIndicators" class="carousel slide carousel-style w-100" 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" src="images/bank-note-euro-bills-paper-money-63635.jpeg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block" src="images/lights-night-unsharp-blured.jpg" alt="Third slide">
<div class="carousel-caption d-none d-md-block">
<h5>Night Lights</h5>
<p>Watch the night lights</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block" src="images/pexels-photo-326259.jpeg" alt="Third slide">
</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>
You can assign fixed height to the carousel-item
selector along with overflow:hidden
property. Try adding this to your css.
.carousel-item {
height: 300px;
overflow: hidden;
width: 100%;
}
.carousel-item img {
width: 100%;
}
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