如何在图像下面移动bootstrap 3轮播标题?

时间:2022-11-03 21:50:16

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

我有这个使用bootstrap 3显示幻灯片图像的html:

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

我试图操纵html和css但无法实现这一点,所以感谢你的帮助。

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

更新:除了本机引导程序,我已经尝试过这些自定义css指令(没有帮助):

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

2 个解决方案

#1


22  

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

首先将标题元素的位置从绝对位置更改为相对位置:

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

Demo

#2


4  

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.

我有一个类似的问题,我希望标题覆盖在大屏幕上的图像上,并在图像下方以较小的尺寸覆盖。我在.carousel-inner可见的溢出。我相信这将是一种有用的替代方法,可以将字幕文本定位在旋转木马图像本身的边界之外,无论其是否是响应元素的一部分。

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.

编辑:您还必须更改轮播的高度(包含div,而不是“内部”)以适应图像的高度加上标题。

.carousel-inner{
overflow: visible;
}

#1


22  

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

首先将标题元素的位置从绝对位置更改为相对位置:

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

Demo

#2


4  

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.

我有一个类似的问题,我希望标题覆盖在大屏幕上的图像上,并在图像下方以较小的尺寸覆盖。我在.carousel-inner可见的溢出。我相信这将是一种有用的替代方法,可以将字幕文本定位在旋转木马图像本身的边界之外,无论其是否是响应元素的一部分。

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.

编辑:您还必须更改轮播的高度(包含div,而不是“内部”)以适应图像的高度加上标题。

.carousel-inner{
overflow: visible;
}