Bootstrap 4 carousel an image does not overlay other images - html

I am writing code with bootstrap 4. On my carousel images there should be another image ( a nice layer on the bottom), but with the code below it appears not on the bottom of the picture, but below it. Maybe you have any ideas how to fix this?
HTML
<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="img.img1.jpg" alt="First slide">
<img class="ex-img" src="img/img2.jpg" alt="orange-img">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/img2.jpg" alt="Second slide">
<img class="ex-img" src="img/img4.jpg" alt="orange-img">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/img5.jpg" alt="Third slide">
<img class="ex-img" src="img/img6.jpg" alt="orange-img">
</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>
CSS
.carousel .slide{
position:absolute;
}
.carousel-item img{
position:relative;
}
.ex-img{
position:relative;
}

I'm not sure what you meant though, but try changing the style like below
<style>
.carousel-item {
position: relative;
}
.ex-img {
position: absolute;
left: 0;
bottom:0;
}
</style>

Related

Can I move Bootstrap Carousel to the right instead of center?

I'm using Bootstrap Carousel, but not sure if it is possible to move the Carousel to the far right instead of putting it in the center. I've looked for an example of it but I could not find any other than moving the indicator to the right. I'd like to move the whole Carousel to the right, so I can have white space on the left. Can I do this with Bootstrap Carousel? Or should I look for some other way?
.mainCarousel {
background-color: whitesmoke;
margin-top: 0;
}
<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">
<div class="mainCarousel">
<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/1.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="images/2.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="images/1.jpg" alt="Third slide">
</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>
Add these 2 classes .w-75 .ml-auto to .mainCarousel see the example.
And if you don't want .w-75 which contains width: 75% !important; you can add custom width to .mainCarousel in your CSS.
.mainCarousel {
background-color: whitesmoke;
margin-top: 0;
}
<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">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<div class="mainCarousel w-75 ml-auto">
<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://images.pexels.com/photos/1051399/pexels-photo-1051399.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://images.pexels.com/photos/2741458/pexels-photo-2741458.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://images.pexels.com/photos/2175211/pexels-photo-2175211.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="Third slide">
</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>
If you only just want to have non-writable whitespace on the left of the carousel, use the accepted answer's approach. In fact, you don't even need to set the width to 75%. You can just add left paddings to the carousel.
If you want to have space on the left of the carousel so that you can put some texts there, and you want it to be responsive, use the grid system to construct the layout, and place the carousel on the right column.
The following is just an example. I have no idea how long you want the carousel to be, and/or when you want the left stacks up on top of the right column:
<div class="container-fluid">
<div class="row">
<div class="col-lg-4">
Writable area
</div>
<div class="col-lg-8">
<div class="mainCarousel" />
</div>
</div>
</div>
At large breakpoint and up:
Below large breakpoint:
demo: https://jsfiddle.net/davidliang2008/sj541uoL/7/

Manual carousel with all aligned images

I have a bootstrap carousel but he is automatic and manual. I wanted to change him in order to use it only manually and I want to separate the items with spaces.
This is my carousel html :
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" style=" width:608px; height: 420px !important;">
<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 src="./assets/image/Meduse-aurelie.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="./assets/image/Merou-lanceole.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="./assets/image/Iguane.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="./assets/image/requin-marcheur.jpg" class="d-block w-100" alt="...">
</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>
And this is my carousel css :
.carousel-item {
margin-left: 20px;
}
I have this result :
Someone can help me please ?

Carousel Height Problem, The default Carousel height is too large

I am trying to shorten the height to 500px from 1000px. Since this is my first time including bootstrap I have difficulty understanding which css class affects the carousel. If you can give me tips or a guide it would be much appreciated
Code
This is set to a max-width of 500px.
Here it is in a Codepen, too.
$('.carousel').carousel({
interval: 2000
})
.carousel-item {
max-height: 500px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/js/bootstrap.bundle.min.js"></script>
<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="http://placeimg.com/1920/1080/1" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="http://placeimg.com/1920/1080/2" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="http://placeimg.com/1920/1080/3" alt="Third slide">
</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 to make carousel fixed overlay for Bootstrap 4.1?

I want to carousel overlay for Bootstrap 4.1 but .carousel-control-prev-icon and carousel-control-next-icon not working. how can i run icon? Not for each slide element. Just one overlay but over slides.
Below html code;
<!-- Start Banner-->
<section id="banner">
<div class="container-fluid">
<div class="row">
<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="bg-overlay">try fixed overlay</div>
<div class="carousel-item active">
<img class="d-block w-100" src="resources/images/image-1.jpg" alt="image slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="resources/images/image-2.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="resources/images/image-3.jpg" alt="Third slide">
</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">Önceki</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">Sonraki</span>
</a>
</div>
</div>
</div>
Below css code;
.bg-overlay {
background-color: rgba(0, 0, 0, 0.5);
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 100%;
z-index: 2;
}
In your css file you can overwrite Bootstraps default classes. You can directly target both arrows css to give them a larger z-index value.
Example:
.carousel-control-prev {
left: 0;
z-index: 3;
}
and
.carousel-control-next {
right: 0;
z-index: 3;
}
This will bring the arrows above your overlay and make them clickable.
Example Codepen
In this example next and previous buttons has an overlay style:
////////////////////////
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<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>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="la.jpg" alt="Los Angeles">
</div>
<div class="item">
<img src="chicago.jpg" alt="Chicago">
</div>
<div class="item">
<img src="ny.jpg" alt="New York">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
////////////////////////

Unexpected white background on top of carousel images in Bootstrap 4

I don't understand why an unexpected white background appears on top of the bootstrap 4 carousel when I apply a black background color. How can I correct this unexpected issue? You can find the example of this issue here https://codepen.io/edquijano/pen/MQxogR Thanks for your input.
<div class="carousel">
<div class="bg-dark">
<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/hero.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="images/hero.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="images/hero.jpg" alt="Third slide">
</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>
</div>
The carousel is enclosed in an overlay div, which comes with an opacity of 0.6. This makes the images look like they have a whitish cast over them.
You can either choose to remove the overlay div or explicity set opacity:1 on the images.
Here is the output with the overlay div removed: https://codepen.io/anon/pen/XZGevv