【问题标题】:margin-top for carousel indicator not working bootstrap轮播指示器的边距顶部不起作用引导程序
【发布时间】:2021-03-21 23:44:07
【问题描述】:

我使用 bootstrap 4 制作了一个轮播,如下所示:

{% if events %}
<div class="text-center my-3">

  <h3 class="font-weight-bold pb-4 mb-0 text-center">Events</h3>

  <div class="carousel slide my-4" data-interval="false" id="carousel-1">

    <div class="carousel-inner">

      {% for item in events %}
        <div
            {% if forloop.counter0 == 0 %}
              class="carousel-item active  "
            {% else %}
              class="carousel-item  "
            {% endif %}>

            <div class="row">
              <div class="col-xs-12 col-sm-12 col-md-5 col-lg-5 col-xl-5 ml-auto">

                <div class="text-right  ">

                  <a class="text-dark"  href="{% url 'events' %}">

                    <div>

                      <h3 class="text-dark" >{{ item.title }}</h3>
                      <p class="text-dark" style="color: #F4F4F4;" > {{item.date}} </p>
                      <p class="text-dark" > {{item.description|safe}} </p>

                    </div>

                  </a>
                </div>

              </div>

              <div class="col-xs-12 col-sm-12 col-md-5 col-lg-5 col-xl-5 mr-auto">
                <img class="img-fluid text-center"  style="max-height: 25vh;" src="{{ item.cover.url }}" alt="image cap">
              </div>
            </div>


        </div>
      {% endfor %}

    </div>

    <div>
      <a class="carousel-control-prev" href="#carousel-1" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"><i class="text-dark fas fa-chevron-left"></i></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carousel-1" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"><i class="text-dark fas fa-chevron-right"></i></span>
            <span class="sr-only">Next</span>
      </a>
    </div>

    <ol class="carousel-indicators">
        {% for item in events %}
        <li data-target="#carousel-1" data-slide-to="{{ forloop.counter0 }}"
          {% if forloop.counter0 == 0 %}
            class="active text-dark"
          {% else %}
            class="text-dark"
          {% endif %}
        ></li>
        {% endfor%}
    </ol>

  </div>

</div>
{% endif %}

我希望轮播指示器有一个上边距,这样它就不会与内容重叠。由于我没有显示图像,因此如果它们覆盖内容,则指示符不适合。 我加了

<style>
.carousel-indicators{
    margin-top: 50px;
  }
</style>

但它不起作用。

我也尝试将 margin-top 添加到 bootstrap.min.css,但它也不起作用。

有什么想法吗?

【问题讨论】:

  • 请自带一个可以工作的sn-p,如果你有一个sn-p可以清楚地显示你的问题,它会比没有sn-p更快地解决你的问题,例如,你可以从 codepen 或 jsfiddle 创建一个 sn-p
  • 是的,你是对的,我考虑下次创建一个 jsfiddle ;)

标签: html css bootstrap-4 carousel


【解决方案1】:

.carousel-indicators 元素绝对定位在.carousel 的底部,因此上边距不会做任何事情。而是用负值覆盖0bottom 值,以将其移至.carousel 下方

.carousel-indicators{
  bottom: -50px;
}

【讨论】:

  • 我在 bootstrap.min.css 中添加了top: 50px;,它成功了!谢谢。
  • 请注意,您不能在引导 CSS 文件中添加单行 CSS,因为这样做非常糟糕
  • 制作您的自定义 CSS 文件并在那里指定,您的问题将得到解决,但不要将其添加到引导 CSS 文件中
猜你喜欢
  • 2018-12-25
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
  • 2021-11-03
  • 1970-01-01
  • 2016-12-06
  • 2013-05-02
  • 2014-02-14
相关资源
最近更新 更多