Bootstrap Carousel:图像不响应?

时间:2014-08-26 20:57:49

标签: html css twitter-bootstrap

首先,我知道这个post然而尝试规定的解决方案对我来说似乎并不适用。我的图像似乎没有与滑块的视口成比例延伸。

我在下面提供了截图... 幻灯片中的灰色部分是默认背景;显然我的图像被轻推到顶部,但没有扩展到整个高度,即500px。

enter image description here

这是我的HTML:

     <!-- Carousel
================================================== -->
<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>
  </ol>
  <div class="carousel-inner">
   <div class="item active">
     <img class="img-responsive" width="100%" height:"500px" src="/img/4a_slider_w992.png" data-src="/img/4a_slider_w992.png" alt="First slide">
      <div class="container">
        <div class="carousel-caption">
          <h1>Another example headline.</h1>
          <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
          <p><a class="btn btn-lg btn-primary" href="#" role="button">Learn more</a></p>
        </div>
      </div>
    </div>
  <!-- repeated -->
     <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
  <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div><!-- /.carousel -->

这是我的css ......

/* CUSTOMIZE THE CAROUSEL
-------------------------------------------------- */

/* Carousel base class */
 .carousel {
  margin-bottom: 20px;
  border-bottom: 1px solid #3f2416;
  z-index: 1000;
  margin-top:-50px !important;
  }

/* Since positioning the image, we need to help out the caption */
.carousel-caption {
 z-index: 10;
 top: 50px;
 }

/* Declare heights because of positioning of img element */
.carousel .item {
 height: 500px; //needed
 background-color: #777;
 width:100%;
 }

当然这是我提到的帖子说的评论出来的CSS ......

// .carousel-inner > .item > img { /*<== as per stackOverFlow*/
//   top: 0;
//   left: 0;
//   min-width: 100%;
//   height: 500px;
// }

1 个答案:

答案 0 :(得分:1)

尝试设置图片的高度以覆盖其父级,并通过删除max-width

按比例缩放
.carousel-inner>.item>img, 
.carousel-inner>.item>a>img{
    height: 100%;
    width: auto;
    max-width: none;
    margin: 0 auto;
}

<强> Demo fiddle