如何将 Bootstrap 轮播指示器更改为点?

新手上路,请多包涵

我正在使用 Bootstrap 4 Beta 2 版本进行轮播。代码如下所示:

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

轮播指示器显示为线条: 在此处输入图像描述

有没有办法可以将指标更改为点而不是线?我认为这是一个引导选项,但我没有找到相关文档。我需要为此编写自定义CSS吗?

原文由 Lance Shi 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.5k
2 个回答

是的,我认为您需要编写自定义 CSS 来将线条变成点。

You just need to override two properties ( width and height ) and add a new one, border-radius , to .carousel-indicators li .

Make width and height values equal eg: 10px each and give a border-radius of 100% .

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

原文由 Ddmteetu 发布,翻译遵循 CC BY-SA 3.0 许可协议

在 bootstrap 5 中,如果您更改评论中的内容,它会起作用。

 .carousel-indicators [data-bs-target] {
    box-sizing: content-box;
    flex: 0 1 auto;
    width: 10px; /* change width */
    height: 10px; /* change height */
    padding: 0;
    margin-right: 3px;
    margin-left: 3px;
    text-indent: -999px;
    cursor: pointer;
    background-color: #fff;
    background-clip: padding-box;
    border: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    opacity: .5;
    transition: opacity .6s ease;
    border-radius: 100%; // /* add border-radius */
}

示例: 点的图像

原文由 TOPAiiN 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题