在Bootstrap Carousel的内容与在背景中滑动的图象

时间:2013-12-18 12:54:52

标签: twitter-bootstrap twitter-bootstrap-3

我有一个带有图像的Slider作为一个滑动组件,我想要放置一个恒定的内容块,无论屏幕大小如何,都将显示在与页面对齐的中心的块中心,如下所示

enter image description here

<div id="homeSlider"> 
    <!-- Slider -->
    <div class="carousel" id="my-carousel">
      <ol class="carousel-indicators">
        <li data-target="#my-carousel" data-slide-to="0" class="active"></li>
        <li data-target="#my-carousel" data-slide-to="1"></li>
        <li data-target="#my-carousel" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner">
        <div class="item active" style="background-image:url(img/slider_img2.jpg);"></div>
        <div class="item" style="background-image:url(img/slider_img1.jpg);"></div>
        <div class="item" style="background-image:url(img/slider_img3.jpg);"></div>
      </div>
      <a href="#my-carousel" class="carousel-control left" data-slide="prev">&lsaquo;</a> <a href="#my-carousel" class="carousel-control right" data-slide="next">&rsaquo;</a> </div>

    <!-- /Slider -->

    <div class="mainPitch">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
            <h1>Reach  out  to  Apartment  Residents</h1>
            <h3>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </h3>
            <div class="mainAction"><a class="btn btn-danger" href="">a</a><a class="btn btn-success" href="">a</a></div>
          </div>
        </div>
      </div>
    </div>
  </div>

3 个答案:

答案 0 :(得分:5)

html for #mainPitch

 <div class="mainPitch" style="position:absolute; top:50px;">
      <div class="container">
        <div class="row">
          <div class="col-xs-6" style="text-align:center;">
            <h1>Reach  out  to  Apartment  Residents</h1>
            <h3>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </h3>
            <div class="mainAction"><a class="btn btn-danger" href="">a</a><a class="btn btn-success" href="">a</a></div>
          </div>
        </div>
      </div>
</div>

将您的轮播包裹在.col-xs-6或根据您的轮播宽度更改课程。

请参阅:http://bootply.com/101530

答案 1 :(得分:1)

请参阅此处。 http://www.sitepoint.com/css-center-position-absolute-div/。我有同样的问题,本文底部的第一条评论为我修复了它。尝试..

left: 0px;
right:0px;
margin: 0 auto;

答案 2 :(得分:0)

<div>
<div class="content-div">Content DIV</div>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <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>
    <div class="carousel-inner" role="listbox">
        <div class="item active">
            <img src="http://placehold.it/1160x600" alt="..." />
            <div class="carousel-caption">This is caption</div>
        </div>
        <div class="item">
            <img src="http://placehold.it/1160x600" alt="..." />
            <div class="carousel-caption">This is caption</div>
        </div>
    </div> <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>

查找CSS部分:

.content-div {
text-align: center;
background: #090;
color: #fff;
width: 50%;
height: 150px;
position:absolute;
top:150px;
z-index:9;}

.carousel-inner{
width:100%;
position:relative;}
@media (min-width: 992px) {
.content-div {
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;}}