Bootstrap 5 Carousel same height with different sizes - html

I am using Bootstrap 5 carousel to show a list of images uploaded from users, so they do not have the same height and width.
I would like to have a carousel with responsive height and scaled/filled images.
This is my HTML + CSS code (images are taken from the web, as an example):
<style>
#carouselExampleCaptions .carousel-item img {
object-fit: cover;
object-position: center;
overflow: hidden;
height:50vh;
}
</style>
<div class="card">
<div class="card-body">
<div class="row g-0">
<div class="col-md-6">
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://englishlive.ef.com/blog/wp-content/uploads/sites/2/2014/07/tall-1024x1535.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://miro.medium.com/max/1400/1*NlA2fRVMV2blpuA0aPEgPA.png" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="http://clipart-library.com/img/1832282.png" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
<div class="col-md-6 p-2">
<ul class="list-group list-group-flush">
<li class="list-group-item"><b>ID:</b> 1</li>
<li class="list-group-item"><b>Uplodaded by:</b> User</li>
<li class="list-group-item"><b>Views:</b> 100</li>
</ul>
</div>
</div>
</div>
</div>
It works not really well since when I simply open browser console images are crushed and captions over images do not suffer changes. Same thing happens if I switch device simulator (on console).
EDIT:
The result I have after #Aryclenio Barros suggestion:
image with large width
image with larghe height

I believe what you are trying to do is:
<style>
#carouselExampleCaptions .carousel-item img {
object-fit: contain;
object-position: center;
overflow: hidden;
height:50vh;
}
</style>
With object-fit: contain you will have the same height but the width will not fill the corresponding parent div, looking like this:
The captions are not showing up because there is a configuration that put a display: none on the md breakpoint by bootstrap. Removing it will show the captions in every screen size.
<div class="carousel-caption">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>

Related

Image not displayed on html

Image is not displayed on the bootstrap carousel template while trying to load it locally.The image loads when the absolute url (online link) is mentioned. I can't see what mistake I might have made.
The folder tree is included in the picture.
I have tried using absolute image links i.e. online links and the code works perfectly.
While trying to insert the pictures locally, I have tried using \ instead of / , renaming the image files and putting the files in different folders .
{% extends 'base.html' %}
{% block title %}
This is the block title.
{% endblock title %}
{% block body %}
</div class='container'>
<div id="carouselExampleCaptions" class="carousel slide">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="cartoon.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="rick_morty.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="rick_morty.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
{% endblock body %}
You need to make sure that the image's src tag is always starting with /, and the images are in the main path of the site, for example: example.com/cartoon.jpg.
So, your images would look something like this:
<img src="/rick_morty.jpg" class="d-block w-100" alt="...">
and the image must be available under yoursiteurl/rick_morty.jpg

Stop carousel from looping

I have a bootstrap v5.2 carousel but it should not loop after the last page.
See the snippet below.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<input class="workflowTitle" value="Accordion Item #1" />
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<div id="carouselExampleDark" class="carousel carousel-dark slide" data-bs-ride="false" data-bs-interval="false">
<div class="">
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="false">
<div class="carousel-inner">
<div class="carousel-item active">
<p class="d-block w-100">I have a Bootstrap Accordion I need to prevent opening of the accordion when textbox is clicked While, if anyone clicks outside the texbox (blue color region) let it expand and shrink as usual.
</p>
<div class="carousel-caption d-none d-md-block">
<h5>First slide label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<p class="d-block w-100">I have a Bootstrap Accordion I need to prevent opening of the accordion when textbox is clicked While, if anyone clicks outside the texbox (blue color region) let it expand and shrink as usual.
</p>
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<p class="d-block w-100">I have a Bootstrap Accordion I need to prevent opening of the accordion when textbox is clicked While, if anyone clicks outside the texbox (blue color region) let it expand and shrink as usual.
</p>
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="">Previous</span>
</button>
<button class="" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="">Next</span>
</button>
</div>
</div>
</div>
</div>
</div>
All you need is to provide a data attribute to your carousel. According to Bootstrap 5 documentation, setting wrap to false will achieve the goal.
<div id="carouselExampleControls"
class="carousel slide"
data-bs-ride="false"
data-bs-wrap="false"> // this is what you need to add.
Reference:
https://getbootstrap.com/docs/5.1/components/carousel/#options

Setting Carousel (Images) Height Equal to Window Height

I have this page that loads a carousel but I want the carousel to fit in the window without having the vertical scrollbar as shown in the picture. How can I achieve that please?
Page:
<div id="carouselIndicators" class="carousel slide" data-bs-ride="carousel" style="margin-bottom:40px;">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner rounded-corners">
<div class="carousel-item active">
<img src="/images/carousel/carosel1.jpg" class="d-block w-100" alt="carosel1">
<div class="carousel-caption d-none d-md-block">
<h1 class="text-success fw-bold fst-italic font-monospace">Seamless Allocation of Subjects</h1>
<p class="text-warning fst-italic">
****************Some Text****************
</p>
</div>
</div>
<div class="carousel-item">
<img src="images/carousel/carosel2.jpg" class="d-block w-100" alt="carosel2">
<div class="carousel-caption d-none d-md-block">
<h1 class="text-success fw-bold fst-italic font-monospace">Even Distribution of Classes</h1>
<p class="text-warning fst-italic">
****************Some Text****************
</p>
</div>
</div>
<div class="carousel-item">
<img src="images/carousel/carosel3.jpg" class="d-block w-100" alt="carosel3">
<div class="carousel-caption d-none d-md-block">
<h1 class="text-success fw-bold fst-italic font-monospace">Class Management</h1>
<p class="text-warning fst-italic">
****************Some Text****************
</p>
</div>
</div>
</div>
<button class="carousel-control-prev" id="#carouselIndicators-prev" type="button" data-bs-target="#carouselIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" id="#carouselIndicators-next" type="button" data-bs-target="#carouselIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Current View:
click to view the rendered view
You need to use slider height as calc attribute For example
height: calc(100vh - 0px); //Increase/decrease the value in pixel as needed
Then increase/decrease the value in pixels so that for every screen your slider will take windows height.
Let me know if this will work for you.

Bootstrap Carousel is not responding

I have been trying to add a carousel to my landing page and come out with a problem, i am able to see the first image of the carousel but the template literally does not slide to the next image. I have copied the template from bootstrap-carousel, i can see the navigators, data-bs-interval not responding, too. My Bootstrap version is 5.1.3. I even tried to add references for Jquery even though I know it's not required. Thank you in advance.
References:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
HTML and CSS codes;
#carouselExampleCaptions img{
max-width: 700px;
margin: auto;
//alignment and resizing
}
<div id="carouselExampleCaptions" class="carousel slide " data-bs-ride="carousel" data-bs-interval="2000">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="/jpg/wood_12.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Özel Üretim</h5>
<p>Masa tasarımı ve boyutlarını sizin tercihinize göre yapılandırıyoruz</p>
</div>
</div>
<div class="carousel-item">
<img src="/jpg/wood_10.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="/jpg/wood_11.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
I copied your code to a Bootsrap 5 page that I currently have open and the slides do seem to work OK. I haven't changed anything except to remove d-none from the carousel-caption's. I am fairly sure that wasn't preventing the slideshow though.
data-bs-interval needs to go on each slide. On each of the Divs which have class="carousel-item"
I just copy pasted your code to a codepen and it seems working fine.
are you sure you added links to jquery, bootstrap css and bootstrap js to ur project?
You can check the codepen here
#carouselExampleCaptions img {
max-width: 700px;
margin: auto;
//alignment and resizing
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div id="carouselExampleCaptions" class="carousel slide " data-bs-ride="carousel" data-bs-interval="2000">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://images.unsplash.com/photo-1564419320408-38e24e038739?ixlib=rb-1.2.1&ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=500&q=60" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Özel Üretim</h5>
<p>Masa tasarımı ve boyutlarını sizin tercihinize göre yapılandırıyoruz</p>
</div>
</div>
<div class="carousel-item">
<img src="https://images.unsplash.com/photo-1646121575186-fe136178cff2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxM3x8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Second slide label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://images.unsplash.com/photo-1646100960029-967036496807?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxN3x8fGVufDB8fHx8&auto=format&fit=crop&w=500&q=60" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h5>Third slide label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>

Bootstrap 5 carousel-caption text disappears when the website is seen on a smaller screen

I am using bootstrap carousal code. My carousal text looks good when seen on the regular size but it disappears when seen on the smaller size screen. It seems the text is getting behind the image. I have tried using z-index, media query for changing font sizes, margins, paddings but it still the same.
HTML code:
<div id="carouselExampleDark" class="carousel carousel-light slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleDark" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="10000">
<img src="images/image1.jpeg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h1>First slide lable</h1>
</div>
</div>
<div class="carousel-item" data-bs-interval="2000">
<img src="images/image2.jpeg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h1>Second slide lable</h1>
</div>
</div>
<div class="carousel-item">
<img src="images/image3.jpeg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h1>Third slide label</h1>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleDark" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
CSS code:
.carousel-caption {
text-align: center;
margin-bottom: 18%;
z-index: 999;
font-size: 100px;
font-family: 'Montserrat', sans-serif;
font-weight: 600;
position: absolute;
padding-left: 20%;
padding-right: 20%;
padding-top: 20%;
}
#media only screen and (max-width: 800px) {
.carousel-caption {
text-align: center;
font-size: 20px;
}
}
You have the classes d-none d-md-block on the captions. This effectively puts display: none from xs and then display: block from md and above. Remove all 3 d-none and your issue will be solved.
Change:
<div class="carousel-caption d-none d-md-block">
// caption
</div>
To:
<div class="carousel-caption">
// caption
</div>
Edit: You actually do not need d-md-block either, given the element is blocked by default.