How to move bootstrap 3 carousel caption below ima

2020-06-12 02:52发布

I have this html that shows slideshow images using bootstrap 3 :

<div class="col-sm-8">



            <div id="myCarousel" class="carousel slide" data-ride="carousel">
            <!-- Indicators -->
            <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>
                <li data-target="#myCarousel" data-slide-to="3"></li>
                <li data-target="#myCarousel" data-slide-to="4"></li>
                <li data-target="#myCarousel" data-slide-to="5"></li>
            </ol>

            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                {% for p in posts %}
                    {% if forloop.counter == 1 %}
                    <div class="item active">
                    {% else %}
                    <div class="item">
                   {% endif %}

                    {% if p.headimage %}
                    <img src="{{ p.headimage.url }}" alt="Image" width="460" height="345">
                     {% endif %}
                      <div class="carousel-caption">
                        <h3>{{ p.title }}</h3>
                        <p>{{ p.teaser }}</p>
                      </div>
                </div>
                {% endfor %}
                </div>

                <!-- Left and right controls -->
                <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                    <span class="sr-only">Previous</span>
                </a>
                <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                </a>
            </div>

</div>

I want caption to be shown below the image, not over it.

I tried to manipulate the html and css but could not achieve this, so appreciate your help.

Update: Apart from native bootstrap, I have tried these custom css directives (which did not help):

.carousel-inner { padding-bottom:95px; }
.carousel-caption { bottom:-95px; }

2条回答
We Are One
2楼-- · 2020-06-12 02:59

Start by changing the position of the caption element from absolute to relative:

.carousel-caption {
    position: relative;
    left: auto;
    right: auto;
}

Demo

查看更多
Melony?
3楼-- · 2020-06-12 03:00

I had a similar issue where I wanted the caption to be overlaid on the image on a large screen, and below the image in smaller sizes. I made overflow in .carousel-inner visible. I believe this would be a helpful, alternate way to position the caption text outside of the bound of the carousel images itself regardless of whether its part of a responsive element or not.

Edit: You must also change the height of the carousel (the containing div, not "inner") to accommodate the height of the image plus the caption.

.carousel-inner{
overflow: visible;
}
查看更多
登录 后发表回答