【问题标题】:carousel indicators bootstrap 4 not taking the css style轮播指标引导程序 4 不采用 css 样式
【发布时间】:2019-01-14 09:17:07
【问题描述】:

我正在尝试为 bootstrap 4 轮播指示器设置样式,如下图所示,但我无法这样做。

.carousel-indicators {
    width: auto;
    padding: 8px 18px;
    background-color: rgba(96,107,114,.8);
    border-radius: 18px;
    line-height: 0;
   
}


.carousel-indicators li {
  border-radius: 50% !important;
  width: 12px;
  height: 12px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<ul 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>
        </ul>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

在我的情况下,背景的宽度更大。我尝试过定位和翻译,但无法这样做。我无法像上图那样实现。 谁能帮我解决这个问题。

【问题讨论】:

    标签: html css twitter-bootstrap bootstrap-4


    【解决方案1】:

    您可以使用!important 使其工作。这是必需的,因为它需要覆盖引导程序的样式。

    强烈建议不要使用此方法。我建议您使用 Bootstrap Sass 来生成您需要的 css。您可以在 _variables 文件中定义样式的变量。


    好的,我在回答之前没有阅读完整的问题。您还需要覆盖一些默认的引导类以获得类似的指标。

    .carousel-indicators {
      /* required to override bootstrap */
      right: unset !important;
      left: unset !important;
      padding-left: 18px !important;
      margin-right: unset !important;
      margin-left: unset !important;
      /* your css styles */
      width: auto;
      padding: 8px 18px;
      background-color: rgba(96, 107, 114, .8);
      border-radius: 18px;
      line-height: 0;
    }
    
    .carousel-indicators li {
      border-radius: 50% !important;
      width: 12px !important;
      height: 12px !important;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    
    <div class="row no-gutters justify-content-center">
      <ul 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>
      </ul>
    </div>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

    【讨论】:

    • @ShaswatiBhattacharyya 是的,我已经更新了我的 sn-p。我也对 html 进行了一些更改以使其居中。如果你不想插入新节点,你可以使用父类做类似的样式。
    猜你喜欢
    • 1970-01-01
    • 2019-10-29
    • 2019-10-24
    • 2020-12-11
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    相关资源
    最近更新 更多