简体   繁体   English

"Bootstrap 4轮播指示器未出现"

[英]Bootstrap 4 Carousel Indicators are not appearing

I'm trying to create a carousel slider with carousel indicators at the bottom using Bootstrap-4.1.3.我正在尝试使用 Bootstrap-4.1.3 创建一个底部带有轮播指示器的轮播滑块。 The problem is that the carousel indicators are invisible, but they do work when you click them.问题是轮播指示器是不可见的,但是当您单击它们时它们确实起作用。

I've already tried z-index, and background colors on the indicators, but they don't seem to work.我已经在指标上尝试过 z-index 和背景颜色,但它们似乎不起作用。

Here is my code:这是我的代码:

 .carousel-indicators { z-index: 3; #slide-buttons { background-color: #999 !important; background-color: rgba(70, 70, 70, .25) !important; } .active { background-color: #444 !important; } }
 <div class="carousel slide col-9 mx-auto pt-5 position-relative" data-ride="carousel" id="slides"> <!--Carousel Content--> <div class="carousel-content carousel-inner" role="listbox"> <div class="slide-1 col-12 carousel-item active" id="slide1"> <h5>Example</h5> </div> <div class="slide-2 col-12 carousel-item" id="slide2"> <h5>Example</h5> </div> <div class="slide-3 col-12 carousel-item" id="slide3"> <h5>Example</h5> </div> </div> <!-- Carousel Indicators --> <ul class="carousel-indicators mt-5 pt-5 "> <li data-target="#slides" id="slides-buttons" data-slide-to="0" class="active"></li> <li data-target="#slides" id="slides-buttons" data-slide-to="1" class=" "></li> <li data-target="#slides" id="slides-buttons" data-slide-to="2" class=" "></li> </ul> </div>

You should not use the same id multiple times on your page.您不应在页面上多次使用相同的 ID。 Try using this solution instead:尝试改用此解决方案:

 .carousel .carousel-indicators li { background-color: red; } .carousel .carousel-indicators li.active { background-color: blue; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/> <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://cdn.pixabay.com/photo/2016/06/18/17/42/image-1465348_1280.jpg" alt="First slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="https://cdn.pixabay.com/photo/2016/06/18/17/42/image-1465348_1280.jpg" alt="Second slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="https://cdn.pixabay.com/photo/2016/06/18/17/42/image-1465348_1280.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>

There is a typepo error in your code css id.您的代码 css id 中存在 typepo 错误。 'slide s -buttons' and '#slide-buttons 'slide s -buttons' 和 '#slide-buttons

Based on Cristiano Soares solution, I have also added some further suggestions.基于 Cristiano Soares 的解决方案,我还添加了一些进一步的建议。

To ensure that the main carousel component wrapper has indicators set to active;确保主要轮播组件包装器的指标设置为活动;

<Carousel indicators={true} .... <Item><ProjectImg><Caption> ... >

I also added further styling, as I still couldn't see the indicators once they where enabled;我还添加了进一步的样式,因为一旦启用,我仍然看不到指示器;

.carousel-indicators li {
  background-color: red;
  height: 5px;
  width: 20px;
  z-index: 5 !important;
  margin: 0 5px;
  cursor: pointer;
}
.carousel-indicators li.active {
  background-color: blue;
  height: 5px;
  width: 20px;
  z-index: 5 !important;
  padding: 0 5px;
  cursor: pointer;
}

指标示例

I had the same problem with bootstrap 4. Then i figured display of indicators is none.我在 bootstrap 4 上遇到了同样的问题。然后我发现没有显示指标。 so this fixed my problem:所以这解决了我的问题:

.carousel-indicators{
display: block !important;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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