Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i stop my bootstrap carousel from changing size

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>
like image 564
Adam Cole Avatar asked Sep 15 '25 14:09

Adam Cole


1 Answers

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%;
}
like image 140
Aryan Twanju Avatar answered Sep 17 '25 03:09

Aryan Twanju