【问题标题】:Bootstrap Carousel Indicators not working properly引导轮播指示器无法正常工作
【发布时间】:2019-10-06 23:07:33
【问题描述】:

我正在为客户的投资组合设计一个网站。在索引中,我有一个引导轮播。这个轮播展示了不同的项目,我使用文本而不是典型的指标创建了一些指标。我会给你看一张图片,这样你就可以看到了。

所以这是我的问题:幻灯片正在正确更改,当我单击指示器时,它会按预期转到右侧幻灯片。但问题是指标没有显示为“活动”,只有第一个(默认情况下是活动的),因为我在 CSS 上写道,当点击一个指标时(我猜是活动的),我希望它变成橙色。

在图片中,您可以看到橙色的“Facebook”项目,但实际上它显示的图像和我点击的指示器对应于名为“Clasico”的项目。

我不知道该怎么做,因为一切看起来都写得很好,并且在它的位置。

HTML 代码

.carousel {
  position: absolute;
  width: 895px;
  height: 638px;
  margin: 0 auto;
  top: 50%;
  -ms-transform: translateY(-30%);
  transform: translateY(-30%);
  margin-bottom: -30px;
}

.carousel-inner img {
  max-width: 100%;
  max-heigth: 100%;
}

.carousel-caption {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.carousel-indicators {
  margin-bottom: -30px;
  text-align: left;
  float: left;
  color: #999999;
}

.carousel-indicators li,
.carousel-indicators li.other {
  width: 100px;
  background-color: transparent;
  border-radius: 0;
  text-indent: 0;
  <!-- ww w.j a va 2s . c o m-->font-family: 'Raleway', sans-serif;
  font-weight: 400;
  font-size: 19px;
  letter-spacing: 1px;
  margin: 0 2px;
}

.carousel-indicators span {
  margin-right: 20px;
}

.carousel-indicators li.active {
  color: #fcb970;
}

.carousel-indicators li:hover {
  color: #fcb970;
}
<div class="col-xs-12 col-sm-12 col-md-10 col-lg-10 col-xl-10 text-center">
  <div id="slides" class="carousel slide carousel-fade">

    <ul class="carousel-indicators">
      <li data-target="#slides" data-slide-to="0" class="active other number-01"><span>Journey </span></li>
      <li data-target="#slides" data-slide-to="1" class="other number-02"><span>Suchard </span></li>
      <li data-target="#slides" data-slide-to="2" class="other number-03"><span>Ramps </span></li>
      <li data-target="#slides" data-slide-to="3" class="other number-04"><span>Facebook </span></li>
      <li data-target="#slides" data-slide-to="4" class="other number-05"><span>Products </span></li>
      <li data-target="#slides" data-slide-to="5" class="other number-06"><span>Lab </span></li>
      <li data-target="#slides" data-slide-to="6" class="other number-07"><span>Clásico </span></li>
      <li data-target="#slides" data-slide-to="7" class="other number-08"><span>Tribute </span></li>
    </ul>
    <div class="carousel-inner">
      <div class="carousel-item active">
        <a href="https://gonzzzalo.com/work/journey"><img src="img/Journey.jpg"></a>
      </div>
      <div class="carousel-item">
        <a href="https://gonzzzalo.com/work/suchard"><img src="img/Suchard.jpg"></a>
      </div>
      <div class="carousel-item">
        <a href="https://gonzzzalo.com/work/ramps"><img src="img/Tutaller.jpg"></a>
      </div>
      <div class="carousel-item">
        <a href="https://gonzzzalo.com/work/facebook-year-on-review"><img src="img/Facebook.jpg"></a>
      </div>
      <div class="carousel-item">
        <a href="https://gonzzzalo.com/work/devices"><img src="img/Products.jpg"></a>
      </div>
      <div class="carousel-item">
        <a href="https://gonzzzalo.com/work/varios"><img src="img/LAB.jpg"></a>
      </div>
      <div class="carousel-item">
        <a href="https://gonzzzalo.com/work/clasico"><img src="img/Clasico.jpg"></a>
      </div>
      <div class="carousel-item">
        <a href="https://gonzzzalo.com/work/tribute"><img src="img/Tribute.jpg"></a>
      </div>
    </div>

  </div>
</div>

【问题讨论】:

  • 你用的是什么浏览器?在 Chrome 和 Firefox 中似乎都可以正常工作。我点击链接,它们被适当地染成橙色。
  • 我的一切都很好,我只收到一个错误,页面试图从未经身份验证的源加载脚本,也许你应该检查你的脚本文件从哪里加载并以安全的方式添加它们.

标签: html css web bootstrap-4 carousel


【解决方案1】:

您的代码在我这边运行良好,但为了您客户的 SEO,您应该为图片添加 alt 属性。

【讨论】:

  • 我的电脑和笔记本电脑都不能正常工作。我在他们两个中都使用 Chrome,但我已经尝试使用 Firefox 和 Safari,但仍然无法正常工作。悬停的浅橙色在所有这些中都很好,但问题是只有第一个按钮(“旅程”)在单击时起作用。单击时其他按钮只是随机变为橙色,甚至最后三个也不起作用。我不知道我还能尝试什么...
  • 如果其中一个指标有效,而另一个无效,则表明其他元素超出了 CSS 的范围。您可以找到导致项目超出范围的原因,或者只是通过为每个元素提供其自己的 id 并将 CSS 应用于每个元素来破解 - 不理想,但它会起作用。
  • 我刚刚解决了。问题是我发布的链接之间还有一些其他链接的跨度为空,所以问题是这些隐藏的链接位于正确的链接之上,所以我无法按下它们。我删除了带有空跨度的链接,现在它可以工作了。
猜你喜欢
  • 2017-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
相关资源
最近更新 更多