Search code examples
htmlcssbootstrap-4carousel

margin-top for carousel indicator not working bootstrap


I made a carousel with bootstrap 4 like the following:

{% 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 %}

I want the carousel-indicator to have a top margin so that it doesn't overlap over the content. since I'm not showing images, the indicators are not suitable if they lay over the content. I added

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

but it is not working.

I also tried to add margin-top to bootstrap.min.css, but it didn't work either.

any ideas?


Solution

  • The .carousel-indicators element is absolute positioned at the bottom of the .carousel so top margin will do nothing. Instead override the bottom value of 0 with a negative value to move it below the .carousel

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