Having an issue with my Bootstrap Carousel where the width changes as it slides.
The carousel starts off fine,
But when it slides,
I want the carousel to stay centered and maintain a fixed width.
Setting a fixed width for carousel-inner works, but it needs to be dynamic based on the uploaded image.
$(document).ready(function() {
$('.carousel').carousel()
});
#myCarousel {
margin-left: 50px;
margin-right: 50px;
height: 100vh;
}
.carousel-inner {
border: 1px solid;
width: fit-content;
margin: auto;
}
.carousel-control {
width: 0%;
}
.car,
car:hover {
color: #000 !important;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0a2afafb4b3b4b2a1b080f4eef6eef1">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div id="myCarousel" class="carousel slide d-flex align-items-center" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img src="https://via.placeholder.com/600x300" alt="a" class="img-responsive">
</div>
<div class="carousel-item">
<img src="https://via.placeholder.com/600x300" alt="b" class="img-responsive">
</div>
<div class="carousel-item">
<img src="https://via.placeholder.com/600x300" alt="c" class="img-responsive">
</div>
<div class="carousel-item">
<img src="https://via.placeholder.com/600x300" alt="d" class="img-responsive">
</div>
</div>
<!-- Left and right controls -->
<button class="car carousel-control-prev" type="button" data-target="#myCarousel" data-slide="prev">
<i class="fas fa-chevron-left fa-2x"></i>
</button>
<button class="car carousel-control-next" type="button" data-target="#myCarousel" data-slide="next">
<i class="fas fa-chevron-right fa-2x"></i>
</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="46242929323532342736067268706877">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
Check out the jsfiddle here.