如何制作Bootstrap旋转木马标题拉伸旋转木马的整个宽度?

时间:2016-05-03 16:41:49

标签: html css twitter-bootstrap carousel caption

我有一个旋转木马,它是页面的整个宽度。现在我需要将旋转木马标题设置为页面的整个宽度以及黄色背景。背景应该是页面的整个宽度,但实际的标题文本应该居中。

这应该是这样的:

This is what it should look like.

这就是现在的样子:

This is what it looks like now.

HTML:

<!--START CAROUSEL-->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" data-interval="false">
  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="../../images/LD/desktop_hero1.png" alt="...">
      <div class="carousel-caption">
        Text for caption 1 here.
      </div>
    </div>
    <div class="item">
      <img src="../../images/LD/desktop_hero2.png" alt="...">
      <div class="carousel-caption">
        Text for caption 2 here.
      </div>
    </div>
    <div class="item">
      <img src="../../images/LD/desktop_hero3.png" alt="...">
      <div class="carousel-caption">
        Text for caption 3 here.
      </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>       
<!--END CAROUSEL-->

CSS:

<style type="text/css">
    .carousel-caption {
     max-width: 100%;
     width:100%;
     background-color: #ffb81c;
    }
</style>

2 个答案:

答案 0 :(得分:5)

carousel-caption类声明div具有绝对定位,其位置从左侧开始为15%。

所以你可以尝试覆盖它。这是css:

.carousel-caption {
    max-width: 100%;
    width:100%;
    background-color: #ffb81c;
    left: 0;
}

答案 1 :(得分:0)

你只需要添加text-align:center becaus实际上它已经使用了全宽

如果某些东西浮动你可以使用clearfix来解决它,请检查这个jsfidlle

title example

<div class="carousel-caption">
    <h1>
    Text for caption 1 here.
    </h1>
  </div>


.carousel-caption h1 {
 max-width: 100%;
 background-color: #ffb81c;
 text-align:center;
}

概率pd。我添加了h1标签以获得更好的语义结构。