While constructing my bootstrap portfolio, I encountered an issue with the carousel at the top. It is overflowing and causing horizontal scrolling.
Carousel HTML:
<div id="carouselExampleIndicators" class="carousel slide" 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>
<li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="img/animewallpaper7.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="img/animewallpaper8.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="img/animewallpaper9.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="img/animewallpaper6.jpg" class="d-block w-100" alt="...">
</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>
CSS code:
/* Ensures the carousel spans the full width of its container */
.carousel {
width: 100%;
margin: 0 auto; /* Centers the carousel within its container */
}
/* Eliminate extra padding and margin around the images */
.carousel-item img {
width: 100%; /* Ensures the image covers the full width of the item */
height: 600px; /* Adjusts the height based on the width */
}
I am seeking a solution to keep the carousel within the browser size without overflowing, while maintaining its responsiveness.