简体   繁体   中英

Bootstrap carousel pagination with previous and next

I am trying to add carousel Left and Right controls in the carousel-indicators list to look like pagination, it's working fine there, but the issue I am facing is INDEX of the carousel-indicators list. Can anyone help to resolve this issue? Thanks in advance:)

Here is the demo:

https://jsfiddle.net/adampavlov/u6pbca1k/11/

.carousel-indicators li {
    width: 32px !important;
    height: 42px !important;
    border-radius: 0;
    line-height: 42px;
    font-weight: 500;
    text-align: center;
    text-indent: inherit;
    border: 1px solid transparent;
    opacity: 1;
    font-size: 18px;
    color: #777777;
}
.carousel-indicators li.active {
    color: #F85A05;
}
.carousel-indicators .prev, 
.carousel-indicators .next {
    opacity: 1;
    width: 50px;
    height: 41px;
    border: 1px solid #D8D8D8;
    font-size: 30px;
    margin: 0 20px;
    text-align: center;
}

This is because your arrows are being treated as indicators as they are inside the div with class carousel-indicators . Instead, they should live outside this div and have their own classes such as carousel-control-prev and carousel-control-next .

The left arrow is being treated as index 0 for the pagination count, instead of the number 1 . So bootstrap is seeing there are 4 elements that it sees as pagination nodes [left arrow, 1, 2, 3, right arrow] , instead of just having [1, 2, 3] .

So, something like this will work:

<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>

<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>

The Bootstrap docs have a more detailed answer to this. Here is the link to the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM