如何移动bootstrap 3 carousel标题下面的图像?

szqfcxe2  于 2023-04-27  发布在  Bootstrap
关注(0)|答案(2)|浏览(120)

我有这个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>

我希望标题显示在图像下方,而不是上方。
我试图操纵的HTML和CSS,但无法实现这一点,所以感谢您的帮助。
更新:除了本机引导,我还尝试了这些自定义css指令(没有帮助):

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

bvuwiixz1#

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

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

Demo

$(function() {
  $('#homeCarousel').carousel({
    interval: 4000
  });
});
#carouselButtons {
  margin-left: 100px;
  position: absolute;
  bottom: 0;
}

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

.carousel .carousel-indicators li {
  background-color: red;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">

<!-- Carousel -->
<div id="homeCarousel" class="carousel slide">
  <!-- Menu -->
  <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>
  </ol>

  <!-- Items -->
  <div class="carousel-inner">
    <!-- Item 1 -->
    <div class="item active">
      <img src="https://via.placeholder.com/1800x600" />

      <div class="container">
        <div class="carousel-caption">
          <h1>Bootstrap 3 Carousel Layout</h1>

          <p>This is an example layout with carousel that uses the Bootstrap 3 styles.</p>
          <p><a class="btn btn-lg btn-primary" href="http://getbootstrap.com">Learn More</a>
          </p>
        </div>
      </div>
    </div>

    <!-- Item 2 -->
    <div class="item">
      <img src="https://via.placeholder.com/1800x600" />
      <div class="container">
        <div class="carousel-caption">
          <h1>Changes to the Grid</h1>

          <p>Bootstrap 3 still features a 12-column grid, but many of the CSS class names have completely changed.</p>
          <p><a class="btn btn-large btn-primary" href="#">Learn more</a>
          </p>
        </div>
      </div>
    </div>

    <!-- Item 3 -->
    <div class="item">
      <img src="https://via.placeholder.com/1800x600" />
      <div class="container">
        <div class="carousel-caption">
          <h1>Percentage-based sizing</h1>

          <p>With "mobile-first" there is now only one percentage-based grid.</p>
          <p><a class="btn btn-large btn-primary" href="#">Browse gallery</a>
          </p>
        </div>
      </div>
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#myCarousel" data-slide="prev">
    <span class="icon-prev"></span>
  </a>
  <a class="right carousel-control" href="#myCarousel" data-slide="next">
    <span class="icon-next"></span>
  </a>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
lymgl2op

lymgl2op2#

我有一个类似的问题,我想在一个大屏幕上的图像上覆盖的标题,并在图像下面以较小的尺寸。我做了溢出在.carousel-inner可见。我相信这将是一个有用的,替代的方式来定位标题文本以外的轮播图像本身的边界,无论它是否是一个响应元素的一部分。
编辑:您还必须更改旋转木马的高度(包含div,而不是“inner”),以适应图像和标题的高度。

.carousel-inner{
overflow: visible;
}

相关问题