CSS 如何在图像下方移动 bootstrap 3 carousel 标题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30125830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:11:13  来源:igfitidea点击:

How to move bootstrap 3 carousel caption below images?

csstwitter-bootstraptwitter-bootstrap-3carousel

提问by Jand

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

我有这个 html,它使用 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.

我试图操纵 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; }

回答by isherwood

Start by changing the position of the caption element from absoluteto relative:

首先将标题元素的位置从absolute更改为relative

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

Demo

演示

回答by Aaron Joseph

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;
}