重新定位Bootstrap Carousel Caption

时间:2016-04-13 00:16:16

标签: html css twitter-bootstrap-3

我正在检查一些过去的SO帖子,但没有一个帮助我。我的问题是我的字幕被推到了不再可见的地步。这可能是由于我的图像尺寸不同。 我怎样才能使每个幻灯片的旋转中心(固定位置)显示在每个幻灯片的正确位置?

以下是我到目前为止的内容:http://www.bootply.com/KcWhRKSTxi

我尝试了什么:前面提到的SO帖子为标题尝试边缘底部。我尝试使用边距底部来推动我的字幕,但有两个问题:(1)这不是响应& (2)有些字幕低于其他字幕。如果检查我的bootply链接,第二个滑块中的标题是可见的,因为图像是最小的(垂直方向)。换句话说,即使我使用margin-bottom,一些字幕也会比其他字幕更高/更低。在我目前的实现中,您将看不到图像1或3上的标题,因为它们被推到3个点(图像选择器)以下。

这是我的代码:

<html>
<head>
  <link rel="stylesheet" type="text/css" href="main.css">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner">
    <div class="item active peopleCarouselImg">
      <img class="peopleCarouselImg" src="https://images.unsplash.com/photo-1440637475816-2e8bf1d4b6f3?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=9000dbcc94e0bad6c5005dc1d867b105">
      <div class="carousel-caption">
        <h3>Caption Text</h3>
      </div>
    </div>
    <div class="item">
      <img class="peopleCarouselImg" src="https://images.unsplash.com/photo-1446645681877-acde17e336a9?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=d8507a72935161039a62fbd8bba41283">
      <div class="carousel-caption">
        <h3>Caption Text</h3>
      </div>
    </div>
    <div class="item">
      <img class="peopleCarouselImg" src="https://images.unsplash.com/photo-1443808709349-353c8b390400?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=ae16ad1553fa2305bdab4a73f583a725">
      <div class="carousel-caption">
        <h3>Caption Text</h3>
      </div>
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>
</div> <!-- Carousel -->

<script src="js/jquery-2.2.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>




.carousel {
  max-height: 600px;
  overflow: hidden;
}

.item img {
    min-width: 100%;
    height: auto;
}

.carousel-caption {
  margin-bottom: 100px;
}

1 个答案:

答案 0 :(得分:4)

如果您为.carousel-inner>.item提供最大高度,则可以使用top和transform css函数垂直对齐carousel-caption内容:

carousel-inner>.item {
    position: relative;
    max-height: 600px;
}
.carousel-caption
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

示例:http://www.bootply.com/H08K4Hxk3C