Carousel image size problem with different sized images - html

In my ecommerce project, I'm creating a carousel but, unfortunately, the size of each image is different. I want all images to fit the same size frame despite their original sizes.
<div id="carouselExampleControls" class="carousel slide w-100 p-3 h-1" data-ride="carousel">
<div class="carousel-inner">
<h1>Hot & Trends</h1>
<hr>
<div class="carousel-item active">
<img src="media/images/1.jpg" class="img-fluid" alt="First Product">
<div class="carousel-caption d-none d-md-block">
<h5>Product Name</h5>
<p>Description</p>
</div>
</div>
<div class="carousel-item">
<img src="media/images/2.jpg" class="img-fluid" alt="Second Product">
<div class="carousel-caption d-none d-md-block">
<h5>Product Name</h5>
<p>Description</p>
</div>
</div>
<div class="carousel-item">
<img src="media/images/3.jpg" class="img-fluid" alt="Third Product">
<div class="carousel-caption d-none d-md-block">
<h5>Product Name</h5>
<p>Description</p>
</div>
</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>
<hr>
</div>

select the img and set width and heigh of image 100%
the problem will solve

HTML-Code:
<section id="slider">
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleControls" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleControls" data-slide-to="1"></li>
<li data-target="#carouselExampleControls" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item carousel-image-1 active">
<div class="container">
<div class="carousel-caption text-right mb-5">
<h5 class="display-3">Product Name</h5>
<p class="lead">Description</p>
</div>
</div>
</div>
<div class="carousel-item carousel-image-2">
<div class="container">
<div class="carousel-caption text-right mb-5">
<h5 class="display-3">Product Name</h5>
<p class="lead">Description</p>
</div>
</div>
</div>
<div class="carousel-item carousel-image-3">
<div class="container">
<div class="carousel-caption text-right mb-5">
<h5 class="display-3">Product Name</h5>
<p class="lead">Description</p>
</div>
</div>
</div>
</div>
<a href="#carouselExampleControls" data-slide="prev" class="carousel-control-prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a href="#carouselExampleControls" data-slide="next" class="carousel-control-next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</section>
CSS-Code:
.carousel-item {
height: 450px;
}
.carousel-image-1 {
background: url('../image/image1.jpg');
background-size: cover;
}
This will work fine..

Look like this example. I hope it is as you imagined it. Now you just have to adjust your code like this ...
.carousel {
height: 200px;
}
.carousel-item,
.carousel-inner,
.carousel-inner img {
height: 100%;
width: auto;
}
.carousel-item {
text-align: center;
}
#portfolio {
background: #356;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js" ></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" ></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<section id="portfolio" class="page-section">
<div id="reviews" class="container-fluid">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class='img-fluid' src="https://images.pexels.com/photos/2409628/pexels-photo-2409628.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="...">
<div class="carousel-caption d-md-block">
<h5>Title</h5>
<p>Description</p>
</div>
</div>
<div class="carousel-item">
<img class='img-fluid' src="https://images.unsplash.com/photo-1542141372-98a047557466?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=752&q=80" alt="...">
<div class="carousel-caption d-md-block">
<h5>Title</h5>
<p>Description</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" 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="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>

Related

Button on carousel indicator

I have a website that uses bootstrap, I have a issue with carousel indicator the Know more button on the captain not working on most screens specifically a big screen.
My code:
<section class="slider_section">
<div id="myCarousel" class="carousel slide banner-main" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="first-slide" src="images/image1.png" alt="First slide">
<div class="container ">
<div class="carousel-caption relative d-block">
<h1><br><strong class="cur">Person 1</strong></h1>
<p>Admin</p>
<div class="button_section"> <a class="main_bt" href="person1.html">Know More</a></div>
</div>
</div>
</div>
<div class="carousel-item">
<img class="first-slide" src="images/image2.png" alt="First slide">
<div class="container">
<div class="carousel-caption relative d-block">
<h1><br><strong class="cur"> Person 2</strong></h1>
<p> User</p>
<div class="button_section"> <a class="main_bt" href="person2.html">Know More</a></div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev" style="width: 5%;">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next" style="width: 5%;">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</section>
What is the issue and how do you solve it??

Fit the image inside the carousel, cant seem to fix it

I am trying to fit the image inside the carousel, but I can't seem to fix it. Here is my css code:
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="images/Products/keyboard.jpg" alt="First slide">
<div class="carousel-caption d-md-block">
<h5 style="color:black">Welcome to LebShops</h5>
<p style="color:black">Proud to be Lebanese</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="images/Products/mouse.jpg" alt="Second slide">
<div class="carousel-caption d-md-block">
<h5 style="color:black">Enjoy our vast selection of products</h5>
<p style="color:black">Cash on delivery</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="images/Products/airpods.jpg" alt="Third slide">
<div class="carousel-caption d-md-block">
<h5 style="color:black">Whatever you need we got it !</h5>
<p style="color:black">Cash on delivery</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" 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="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
How can I fit my picture inside this carousel?
I've used css to adjust its height
I've checked other people's questions but it didnt help me.
Please see the below snippet. I have used different size images in the gallery.
The only change you need to add is css
img{
object-fit: cover;
vertical-align: middle;
border-style: none;
height: 70vh;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="https://picsum.photos/id/100/200/250" alt="First slide">
<div class="carousel-caption d-md-block">
<h5 style="color:black">Welcome to LebShops</h5>
<p style="color:black">Proud to be Lebanese</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://picsum.photos/id/100/500/300" alt="Second slide">
<div class="carousel-caption d-md-block">
<h5 style="color:black">Enjoy our vast selection of products</h5>
<p style="color:black">Cash on delivery</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://picsum.photos/id/100/300/350" alt="Third slide">
<div class="carousel-caption d-md-block">
<h5 style="color:black">Whatever you need we got it !</h5>
<p style="color:black">Cash on delivery</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" 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="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

Cant make different carousels work properly

In my page, I have multiple games one below the other.
Each game has a distinct carousel.
The problem is that only the first one works as expected.
All the other carousels when the next or previous button is pressed they change the images of the first carousel. They still auto slide though.
I want a way to make each one of the carousels to work distinctly.
I tried to use an i = 0 for the ids to make them work distinctly but that didnt work as expected since none of them worked.
Also, the other issue that I am facing is that when the carousel button is pressed this black background appears carousel-control.
Any thoughts?
index.html.erb
is inside a loop
here is my code
<div id="carouselId" class="carousel slide" data-ride="carousel" style = "width:450px; height: 250px; ">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carouselId" data-slide-to="0" class="active"></li>
<li data-target="#carouselId" data-slide-to="1"></li>
<li data-target="#carouselId" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<%=image_tag "#{#stadio.stadium_name}/1.jpg" %>
</div>
<div class="item">
<%=image_tag "#{#stadio.stadium_name}/2.jpg" %>
</div>
<div class="item">
<%= image_tag "#{#stadio.stadium_name}/3.jpg" %>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#carouselId" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true" ></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carouselId" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true" ></span>
<span class="sr-only">Next</span>
</a>
</div>
<div class="container">
<div class="row" id="row1">
<h1>400x400</h1>
<div class="bd-example">
<div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleCaptions" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleCaptions" data-slide-to="1" class=""></li>
<li data-target="#carouselExampleCaptions" data-slide-to="2" class=""></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="https://placebear.com/400/400" alt="400x400" />
<div class="carousel-caption d-none d-md-block">
<h3>400x400</h3>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="http://www.fillmurray.com/g/400/400" alt="400x400" />
<div class="carousel-caption d-none d-md-block">
<h3>400x400</h3>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="https://placekitten.com/g/400/400" alt="400x400" />
<div class="carousel-caption d-none d-md-block">
<h3>400x400</h3>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleCaptions" 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="#carouselExampleCaptions" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<div class="row" id="row2">
<div class="bd-example">
<h1>600x600</h1>
<div id="carouselExampleCaptions2" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleCaptions2" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleCaptions2" data-slide-to="1" class=""></li>
<li data-target="#carouselExampleCaptions2" data-slide-to="2" class=""></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="https://placebear.com/600/600" alt="600x600" />
<div class="carousel-caption d-none d-md-block">
<h3>600x600</h3>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="http://www.fillmurray.com/g/600/600" alt="600x600" />
<div class="carousel-caption d-none d-md-block">
<h3>600x600</h3>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="https://placekitten.com/g/600/600" alt="600x600" />
<div class="carousel-caption d-none d-md-block">
<h3>600x600</h3>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleCaptions2" 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="#carouselExampleCaptions2" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<div class="row" id="row3">
<h1>250x250</h1>
<div class="bd-example">
<div id="carouselExampleCaptions3" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleCaptions3" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleCaptions3" data-slide-to="1" class=""></li>
<li data-target="#carouselExampleCaptions3" data-slide-to="2" class=""></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="https://placebear.com/250/250" alt="250x250" />
<div class="carousel-caption d-none d-md-block">
<h3>250x250</h3>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="http://www.fillmurray.com/g/250/250" alt="250x250" />
<div class="carousel-caption d-none d-md-block">
<h3>250x250</h3>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="https://placekitten.com/g/250/250" alt="250x250" />
<div class="carousel-caption d-none d-md-block">
<h3>250x250</h3>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleCaptions3" 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="#carouselExampleCaptions3" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</div>

Bootstrap 4 - Carousel with fixed background

I would like to create a carousel with a fixed background. Only the text should change.
I tried to put the same background-image into every slide but I don't like the switch animation. I think it would be better if only the text would change.
My code:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="first-slide" src="img/earth1.jpg" alt="First slide">
<div class="container">
<div class="carousel-caption text-left">
<h1>TEXT 1</h1>
<p id="screen"></p>
<p>text1</p>
</div>
</div>
</div>
<div class="carousel-item">
<img class="second-slide" src="img/earth1.jpg" alt="Second slide">
<div class="container">
<div class="carousel-caption">
<h1>TEXT 2</h1>
<p id="screen"></p>
<p>text2</p>
</div>
</div>
</div>
<div class="carousel-item">
<img class="third-slide" src="img/earth1.jpg" alt="Third slide">
<div class="container">
<div class="carousel-caption text-right">
<h1>TEXT 3</h1>
<p id="screen"></p>
<p>text3</p>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
What do I need to add?
Thank you,
Jay
you should try this: add new div above carousel item as shown below and set background image to it whatever you want, you can get same image on every slide, just style your content inside carousel item. you can also set min height to background image as shown in below code.
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="img" style="background-image: url('your image path');">
<div class="carousel-item active">
<img class="first-slide" src="img/earth1.jpg" alt="First slide">
<div class="container">
<div class="carousel-caption text-left">
<h1>TEXT 1</h1>
<p id="screen"></p>
<p>text1</p>
</div>
</div>
</div>
<div class="carousel-item">
<img class="second-slide" src="img/earth1.jpg" alt="Second slide">
<div class="container">
<div class="carousel-caption">
<h1>TEXT 2</h1>
<p id="screen"></p>
<p>text2</p>
</div>
</div>
</div>
<div class="carousel-item">
<img class="third-slide" src="img/earth1.jpg" alt="Third slide">
<div class="container">
<div class="carousel-caption text-right">
<h1>TEXT 3</h1>
<p id="screen"></p>
<p>text3</p>
</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<style type="text/css">
.img{
background-repeat: no-repeat;
background-size: cover;
background-position: center;
min-height:400px;
}
</style>

full width carousel in bootstrap 4 (alpha 6)

<div class="container-fluid" >
<div class="row">
<section class="col-12">
<div class="">
<div class="row">
<section class="col-sm-12">
</div>
<div class="carousel slide" id="featured" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#featured" data-slide-to="0" class="active"></li>
<li data-target="#featured" data-slide-to="1"></li>
<li data-target="#featured" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block img-fluid" src="_images/Slider_1.jpg" alt="slider1">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="_images/Slider_2.jpg" alt="slider2">
<div class="carousel-caption d-none d-md-block">
<h3>Jadon Events</h3>
<p>We organize your events like you cannot even imagine</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="_images/Slider_3.jpg" alt="slider3">
</div>
</div>
<a class="carousel-control-prev" href="#featured" role="button" data-slide="prev"><span class="carousel-control-prev-icon" aria-hidden="true">
<span class="sr-only">Previous</span>
</span></a>
<a class="carousel-control-next" href="#featured" role="button" data-slide="prev"><span class="carousel-control-next-icon" aria-hidden="true">
<span class="sr-only">Next</span>
</span></a>
</div>
</section>
</div>
</div>
I have figured out how to make slider in bootstrap, but now I am stuck with full width slider.
how can I make my carousel full width? I removed container classes but it makes some scroll at bottom which is not good for responsiveness
Try the following code and change images with yours.
<div class="carousel slide" id="featured" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#featured" data-slide-to="0" class="active"></li>
<li data-target="#featured" data-slide-to="1"></li>
<li data-target="#featured" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block img-fluid" src="http://placehold.it/2100x300" alt="slider1">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="http://placehold.it/2100x300" alt="slider2">
<div class="carousel-caption d-none d-md-block">
<h3>Jadon Events</h3>
<p>We organize your events like you cannot even imagine</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="http://placehold.it/2100x300" alt="slider3">
</div>
</div>
<a class="carousel-control-prev" href="#featured" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true">
<span class="sr-only">Previous</span>
</span>
</a>
<a class="carousel-control-next" href="#featured" role="button" data-slide="prev">
<span class="carousel-control-next-icon" aria-hidden="true">
<span class="sr-only">Next</span>
</span>
</a>
</div>