I am using Bootstrap v5.3.3 Carousel. My problem encountered is that the Carousel shows enlarged image when pressing next or previous if the carousel is wrapped in float-start
class.
The minimal codes are here:
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-12">
<div class="float-start">
<div id="carousel_project" class="carousel slide img-fluid me-3 mb-3">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://place-hold.it/800x800/F00" class="d-block w-100" alt="" />
</div>
<div class="carousel-item">
<img src="https://place-hold.it/800x800/00F" class="d-block w-100" alt="" />
</div>
<div class="carousel-item">
<img src="https://place-hold.it/800x800/0F0" class="d-block w-100" alt="" />
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carousel_project" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carousel_project" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
</button>
</div>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla interdum blandit nisi a tincidunt. Nunc dapibus nibh quis sapien vehicula venenatis. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ullamcorper lectus sit amet mollis pretium. Praesent quam tellus, hendrerit id lobortis vitae, facilisis sed tellus. Etiam magna dui, sodales non enim a, aliquet vulputate libero. Phasellus dictum, lacus vel congue tincidunt, eros velit tincidunt dolor, eget dignissim lacus lacus sed ligula. Praesent quis eros blandit sem egestas tincidunt et at libero.</p>
<p>Phasellus vel laoreet arcu. Quisque dignissim quam ac odio viverra, ac tristique nisi elementum. Curabitur et porta ante, nec pellentesque ligula. Sed accumsan finibus convallis. Donec eu venenatis diam. Suspendisse ornare odio enim, et laoreet risus lobortis vel. Sed lobortis nisl sem, sed commodo augue elementum sit amet. Cras suscipit nisl sed blandit hendrerit. Sed nec purus vel tellus tincidunt malesuada.</p>
<p>Quisque non mi et tellus dictum dapibus. Cras sit amet interdum dui. Maecenas vestibulum fringilla feugiat. Morbi feugiat lacus volutpat malesuada euismod. Sed ullamcorper dui ac nulla commodo condimentum. Proin finibus felis a est volutpat ultrices. Donec non libero et eros aliquet facilisis. Morbi pharetra lobortis dolor. In non mauris at arcu eleifend lobortis a in ex. Aenean elementum, neque vitae rutrum condimentum, justo sapien tempus arcu, ut convallis elit ex quis nisl. Cras ullamcorper, orci a volutpat sagittis, eros nulla ornare neque, quis blandit odio lorem nec nibh. Nullam egestas ex et pellentesque egestas. Duis faucibus aliquam fermentum. Nullam ac luctus diam. Quisque sed dui tortor. Maecenas nunc quam, maximus a pellentesque ac, malesuada ac augue.</p>
<p>Curabitur suscipit urna sed mauris aliquam elementum. Duis at tellus eu sem bibendum lacinia. Suspendisse velit tortor, eleifend a ligula eget, volutpat tincidunt metus. Cras molestie, purus ut laoreet fermentum, nisl lorem rhoncus orci, nec scelerisque eros mi non urna. Ut lacinia, lorem id cursus hendrerit, tortor urna vehicula nulla, et lobortis dolor elit id est. Mauris vulputate eros eget malesuada egestas. Sed congue et sapien et lacinia. Duis vulputate magna id fermentum ornare. Praesent vel orci ultrices, condimentum nisl id, lacinia eros. Aenean cursus malesuada augue, id maximus purus scelerisque in. Morbi maximus tellus vel leo pretium imperdiet. Morbi dignissim eros a erat volutpat, sit amet interdum elit malesuada. Ut augue arcu, ultrices eu congue in, convallis nec lacus. Donec sapien ipsum, ultrices ac dolor quis, rhoncus dictum nunc. Vestibulum finibus nulla nec leo viverra, in rutrum felis maximus.</p>
<p>Aliquam semper mi sit amet finibus vestibulum. Aenean in nisi non lectus cursus placerat interdum eu mi. Quisque finibus ligula at urna efficitur, vitae ornare metus mollis. Ut non euismod dui, ac mollis urna. Pellentesque at ligula at nunc convallis interdum ac vel velit. Cras ullamcorper elit pulvinar turpis suscipit, vel volutpat quam ultrices. Aliquam aliquam diam urna, id luctus nulla sodales eget. Nunc rutrum turpis at purus fermentum, nec finibus nunc convallis. Donec faucibus erat turpis, eleifend gravida nibh gravida non. Sed venenatis mollis orci id euismod.</p>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
No additional CSS or JS is attached to affect its results. You can find the JSFiddle here.
How can I fix the sizing problem? Thanks.
2
Answers
That’s common issue width carousel plugins when you don’t give an exact width on carousel item, this also happen in slickjs and splidejs.
So easy way to fix it will be to set an width like 300px (or what ever unit and value u wish)
Looks like img-fluid causing this effect of image resizing.
A very good explanation of the same problem by these folks are really amazing.
Bootstrap carousel resizing image