Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position carousel indicators in Bootstrap 4

I am trying to move the indicators under the slider image by giving .carousel-indicators a bottom: -50px; but the indicators just disappear. Now I am guessing this has something to do with the overflow:hidden of the slider but I can't figure it out.

Here is my code:

<div id="slider" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#slider" data-slide-to="0" class="active"></li>
        <li data-target="#slider" data-slide-to="1"></li>
        <li data-target="#slider" data-slide-to="2"></li>
        <li data-target="#slider" data-slide-to="3"></li>
        <li data-target="#slider" data-slide-to="4"></li>
    </ol>

    <div class="carousel-inner">
        <div class="carousel-item active">
            <img class="d-block w-100" src="header.jpg">
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="slider2.jpg">
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="slider3.jpg">
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="slider4.jpeg">
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="slider5.jpeg">
        </div>
    </div>
</div>

and CSS here:

#slider {
    height: 350px;
    overflow: hidden;
    width: 100%;
}
.carousel-indicators li {
    width: 10px;
    height: 10px;
    border-radius: 100%;
}
.carousel-indicators {
    bottom: -50px;
}
like image 972
Andrei Lazar Avatar asked Jan 17 '18 23:01

Andrei Lazar


3 Answers

Setting bottom: -50px on .carousel-indicators works fine to move the indicators below the carousel, however the result is not visible because of the overflow: hidden, as you suspected correctly. The indicators are simply clipped, as they get out of the bounding box of the carousel.

Instead of setting the height and the overflow property of the #slider itself, I would suggest to fix the height via the .carousel-item class like as follows:

.carousel-item {
    height: 350px;
}

.carousel-indicators li {
    width: 10px;
    height: 10px;
    border-radius: 100%;
}
.carousel-indicators {
    bottom: -50px;
}

This is not interfering with the positioning of the indicators.

A working example is available as a Codepen.

like image 135
dferenc Avatar answered Oct 28 '22 16:10

dferenc


Using this code worked for me!

 .carousel-indicator {
   position: relative;
   bottom: -50px;
 }

This pushed my indicators down just enough to get my paragraph visible.

like image 28
Reece Anderson Avatar answered Oct 28 '22 17:10

Reece Anderson


I was also having this problem recently, but I solve it by setting the div flex-direction: column-reverse. This might be too late but I think it can help those who are encountering the same problem.

like image 1
jeppree Avatar answered Oct 28 '22 15:10

jeppree