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
Related
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
I've taken some code directly from Bootstrap 5 to create a carousel, however for some reason the images won't cycle. I've tried multiple different images and I can't figure out why it isn't working. I've read the Bootstrap doc and I can't figure out what I'm missing. Carousel code:
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item">
<img src="https://www.ane-vert.com/wp-content/uploads/2019/01/terace4096x2048.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="https://media-cdn.tripadvisor.com/media/photo-s/05/ce/0f/bf/l-ane-vert.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="https://media-cdn.tripadvisor.com/media/photo-s/05/ce/0f/bf/l-ane-vert.jpg" class="d-block w-100" 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>
Is there another step I'm missing, I've checked I'm using the correct version of Bootstrap
My bad, I'm pretty new to this. Realised that I hadn't required Bootstrap in JS:
app/javascript/packs/application.js:
import "bootstrap"
In the terminal:
yarn add #popperjs/core
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
looks fine on computer, on tablet in horizontal it seems to crop into image "center".. on phones it crops into center even more not showing all the image.
code in source code view (dreamweaver)
<main id="main" class="site-main">
<section id="carousel-1" class="carousel slide section-slide" data-ride="carousel">
<div class="carousel-inner">
<div class="item active" style="background: url(images/bg-1.jpg);">
<div class="container"><img src="http://roncartist.com/images/copyright_protected-1.png" alt="First slide"></div>
</div>
<div class="item" style="background: url(images/bg-2.jpg);">
<div class="container"><img src="http://placehold.it/640x340" alt="Second slide"></div>
</div>
<div class="item" style="background: url(images/bg-3.jpg);">
<div class="container"><img src="http://placehold.it/640x340" alt="Third slide"></div>
</div>
</div>
<a class="left carousel-control" href="#carousel-1" data-slide="prev"><span class="fa fa-chevron-left"></span></a>
<a class="right carousel-control" href="#carousel-1" data-slide="next"><span class="fa fa-chevron-right"></span></a>
example image
You have to aplly background-size:cover to the element .item
It stretch the background image to completely cover the content area.
Let me know if works.
here is the homepage of my blog www.lowcoupling.com
I'd like not show the left and right arrows in the bootstrap carousel
I have tried
.glyphicon-chevron-right{
display:none;
}
(and the same thing for the left arrow)
but it does not seem to work.
This will hide the buttons
.right.carousel-control, .left.carousel-control {
display: none;
}
If you still want to be able to click where the button is drawn, do:
.right.carousel-control, .left.carousel-control {
opacity: 0;
filter:alpha(opacity=0); /* IE support */
}
I took a quick gander, and you are almost there, but Bootstrap's css is taking precidence over your css. Bootstrap has:
.carousel-control .glyphicon-chevron-right{
...
display:inline-block;
}
If you were to assign an arbitrary point value to this, Bootstrap is providing '2 points' to provide the style 'inline-block'.
Because your css is loaded after Bootstrap, simply putting an extra class (and matching Bootstrap's 2 points) before ".glyphicon-chevron-right" should do the trick.
.carousel .glyphicon-chevron-right{display:none;}
Or, if you want your override to be "stronger", putting an id in front gives your override a higher value (approx 256)
#myCarousel .glyphicon-chevron-right{display:none;}
This will work,
.right.carousel-control,
.left.carousel-control
{
visibility:hidden;
}
there is simple solve for that problem. Just remove "a" tags and with into span tags
before
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</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>
after solved
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
</div>
that's it