I have galleries on multiple pages where the dimensions of the photos are different sizes. I have them in bootstrap carousels and I don't want them to make the dimensions of the carousel itself different, but I still want to show the whole image.
HTML:
<div id="carouselExampleControls" class="carousel slide pt-5 ps-4" data-bs-ride="carousel">
<div class="carousel-inner galleryCarousel">
<div class="carousel-item active">
<a href="http://www.bmillerequipmentsales.com/" target="_blank">
<div class="companyGallery">
<img src="../images/galleries/billmiller/Bill_Gallery_1.jpeg" class="d-block w-100" alt="...">
</div>
</a>
</div>
<div class="carousel-item">
<a href="http://www.bmillerequipmentsales.com/" target="_blank">
<div class="companyGallery">
<img src="../images/galleries/billmiller/Bill_Gallery_2.jpeg" class="d-block w-100" alt="...">
</div>
</a>
</div>
<div class="carousel-item">
<a href="http://www.bmillerequipmentsales.com/" target="_blank">
<div class="companyGallery">
<img src="../images/galleries/billmiller/Bill_Gallery_3.jpeg" class="d-block w-100" alt="...">
</div>
</a>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls"
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="#carouselExampleControls"
data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
CSS:
.companyGallery img {
max-width:100%;
height: auto;
}
.companyGallery {
width: 100%;
height: 100%;
display: grid;
place-content: center;
}
.galleryCarousel {
background-color: #E3E1E1;
max-width: 1280px;
height:720px;
}
I have tried something like this
Related
I want to add a heading and text in an image carousel. When it write h1 or p tags the text goes down under text. I want to keep it in middle of my image. I am using bootstrap framework.
Here is my code:
<section>
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="images/cover/cover-1.png" class="d-block w-100 image-fluid" alt="...">
</div>
<div class="carousel-item">
<img src="images/cover/cover-2.jpg" class="d-block w-100 h-auto image-fluid" alt="...">
</div>
<div class="carousel-item">
<img src="images/cover/cover-3.jpg" class="d-block w-100 image-fluid" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" 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="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</section>
Please refer to the bootstrap documentation for captions on carousel here - https://getbootstrap.com/docs/4.0/components/carousel/#with-captions
If you want to place the text in middle of the image, change/add the below code in your css for carousel-caption
.carousel-caption {
position: absolute;
right: 15%;
top: 45%; // this will help in placing the content in middle vertically
left: 15%;
z-index: 10;
padding-top: 20px;
padding-bottom: 20px;
color: #fff;
text-align: center;
}
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.
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.
I am building an instagram clone & currently working in posts so my question is that, i have created a card and inside of that i have created a div containing posts(images)
but the problem is that, when i upload images with multiple size it straches my card & it doesn't get fit inside of that div. Also my right div changes according images...
This is small image
This is big image
Code:
<div class="mx-auto w-75">
<div class="card my-3">
<div class="card-body p-0">
<div class="row">
<div class="col-sm-8 ms-2 mb-0 ps-1 pe-0">
<div id="carouselExampleFade" class="carousel m-0 slide carousel-fade" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="{% static 'images/post-1.jpg' %}" style="height:auto;" class="d-block w-100 img-fluid" alt="">
</div>
<div class="carousel-item">
<img src="{% static 'images/profile-1.jpg' %}" style="height:auto;" class="d-block w-100 img-fluid" alt="">
</div>
<div class="carousel-item">
<img src="{% static 'images/profile-2.jpg' %}" style="height:auto;" class="d-block w-100 img-fluid" alt="">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleFade" 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="#carouselExampleFade" 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-sm-3 p-0">
<div class="card pt-0" style="width:325px; height:72px; padding:16px; margin-top:-1px;">
<div class="card-body">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
To fit an image in a div, use the css object-fit property.
html code
<div>
<img src="abidjan.jpg" alt="Abidjan" width="400" height="300">
<div>
NB : Note the width and height attributes of the img.
CSS code
img {
width: 200px;
height: 300px;
object-fit: fill;
/* You can also use cover instead of fill but they are different */
}
The image is squished to fit the container of 200x300 pixels (its original aspect ratio is destroyed)
More info here
Sizing property of bootstrap does not apply to the images. If I try to style them inline, everything works as planned, but whenever I try to set it as h-100, the rule does not apply to the images anymore. Can somebody please explain why h-100 is not working?
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100 h-100" src="img/hero-bg_1.jpg" alt="First slide">
<h1> Denim Jackets </h1>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/hero-bg_2.jpg" alt="Second slide" style="height: 100vh">
<h1> text on the second page </h1>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/hero-bg_3.jpg" alt="Third slide" style="height: 100vh">
<h1> text on the third page </h1>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" 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="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Thank you!
In your case you are applying h-100 only to the image of active carousel. It didn't get applied because your parent element don't have a fixed height. Set a height to active class and check.
.active{
height:100vh;
}
I'm sorry in that case you can't apply width or height directly to the image tag.
Use the structure in the following way.
<div class="h-25 d-inline-block" style="width: 120px;
background-color: rgba(0,0,255,.1)"> <img class="rounded mx-auto
d-block" src="img/hero-bg_2.jpg" alt="Second slide" style="height:
100vh"></div