没有图像滚动的CSS Bootstrap Carousel

时间:2015-03-27 16:45:11

标签: jquery css twitter-bootstrap

我想知道是否有人知道图像不会滚动/更改的引导轮播示例,只是文本。

我喜欢静态图像,但滚动文字从右侧出现并消失在左侧。

1 个答案:

答案 0 :(得分:3)

只是不要向每个.item添加图片,而是将图像应用于.carousel对象。由于图像通常会为项目提供某种高度,因此您可能需要应用自己的高度以使其看起来一致。

Stack Snippets中的演示:

.carousel.slide {
  background: url('http://lorempixel.com/400/300/cats/1/');
}
.item {
  height: 200px;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/css/bootstrap.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.2/js/bootstrap.js"></script>

<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" role="listbox">
    <div class="item active">
      <div class="carousel-caption">
        Text 1
      </div>
    </div>
    <div class="item">
      <div class="carousel-caption">
        Text 2
      </div>
    </div>
    <div class="item">
      <div class="carousel-caption">
        Text 3
      </div>
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>