I am building a portfolio with bootstrap and I have carousal on the top, but it is overflowing more which make it to scroll horizontally.
Carousal 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>
here is my css
/* Ensure the carousel spans the full width of its container */
.carousel {
width: 100%;
margin: 0 auto; /* Center the carousel within its container */
}
/* Remove 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 need the carousal to be in the size of browser without overflowing and still be responsive as it is
2
Answers
I am going to assume you are using the latest bootstrap, bootstrap 5. What you just need to do is to make every parent of the image is 100% in height starting from body and html.
This is a short answer, but I hope it can be useful.
Your question doesn’t show this, but from my experience this can happen when you place your full-width carousel inside of a container.
Carousels already have the proper container inside the item div, so they don’t need to be nested in a container.