I used some code from another site to create a Bootstrap 5 carousel. Unfortunately, my carousel left aligns and I would like it to be in the center of the container.
<div class="container-lg my-3">
<div id="myCarousel" class="carousel slide" data-bs-ride="carousel">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-bs-target="#myCarousel" data-bs-slide-to="0" class="active"></li>
<li data-bs-target="#myCarousel" data-bs-slide-to="1"></li>
<li data-bs-target="#myCarousel" data-bs-slide-to="2"></li>
<li data-bs-target="#myCarousel" data-bs-slide-to="3"></li>
<li data-bs-target="#myCarousel" data-bs-slide-to="4"></li>
<li data-bs-target="#myCarousel" data-bs-slide-to="5"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="images/carousel/rt4.jpg" class="d-block w-75" alt="Slide 1">
</div>
<div class="carousel-item">
<img src="images/carousel/rt2.jpg" class="d-block w-75" alt="Slide 2">
</div>
<div class="carousel-item">
<img src="images/carousel/rt3.jpg" class="d-block w-75" alt="Slide 3">
</div>
<div class="carousel-item">
<img src="images/carousel/rt1.jpg" class="d-block w-75" alt="Slide 4">
</div>
<div class="carousel-item">
<img src="images/carousel/rt7.jpg" class="d-block w-75" alt="Slide 5">
</div>
<div class="carousel-item">
<img src="images/carousel/rt8.jpg" class="d-block w-75" alt="Slide 6">
</div>
</div> <!-- Close carousel inner -->
<!-- Carousel controls -->
<a class="carousel-control-prev" href="#myCarousel" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#myCarousel" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div> <!-- Close Carousel div -->
Any suggestions on how to center this?
2
Answers
Add
mx-auto
margin utility class to each image, see: Aligning imagesI think you should change the img tag class to w-100.
if you want to img tag to have class d-75 you should add margin-auto to the img tag.