我无法制作完全响应的旋转木马(bootstrap v4-alpha)

时间:2016-09-09 13:56:51

标签: html twitter-bootstrap css3 twitter-bootstrap-4 bootstrap-4

我想根据这个做一个工作的carousell。 http://v4-alpha.getbootstrap.com/examples/carousel/ 问题是,当我上传我的图像并将其调整到一个小屏幕尺寸时,我得到了图像下的旧图像库的一部分,就像这里一样。 https://postimg.org/image/ocul5jt2t/  我想要的只是我的图像到位,仅此而已。有人可以帮帮我吗?

    <!-- 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" role="listbox">
    <div class="carousel-item active">
      <img src="background1.jpg" alt="First slide">
      <div class="container">
        <div class="carousel-caption text-xs-left">
          <h1>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">Sign up today</a></p>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <img src="background2.jpg" alt="Second 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>
    <div class="carousel-item">
      <img src="background3.jpg" alt="Third slide">
      <div class="container">
        <div class="carousel-caption text-xs-right">
          <h1>One more for good measure.</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">Browse gallery</a></p>
        </div>
      </div>
    </div>
  </div>
  <a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div><!-- /.carousel -->

carousel html是相同的,也是它的css 我想让它适应我的项目,但正如我之前提到的,我将它调整到一个小尺寸时会遇到问题。如果你注意到这张照片,你可以很好地了解它的错误。

 body {
 padding-bottom: 3rem;
 color: #5a5a5a;
 }



.carousel {
 margin-bottom: 4rem;
 }

 .carousel-caption {
  z-index: 10;
 }

 .carousel-item {
 height: 32rem;
 background-color: #777;
 }
 .carousel-item > img {
 position: absolute;
 top: 0;
 left: 0;
 min-width: 100%;
 height: 32rem;
 }

.carousel-indicators {
 top: 1.5rem;
 right: 1.5rem;
 bottom: auto;
 left: auto;
 width: 1rem;
 margin-left: 0;
 }

 .carousel-indicators > li {
 margin-bottom: .25rem;
 }
 @media (min-width: 40em) {

 .carousel-caption p {
 margin-bottom: 1.25rem;
 font-size: 1.25rem;
 line-height: 1.4;
 }

 .featurette-heading {
 font-size: 50px;
 }
 }

 @media (min-width: 62em) {
 .featurette-heading {
 margin-top: 7rem;
 }
 }

1 个答案:

答案 0 :(得分:0)

这是BS 4 alpha的一个已知问题:https://github.com/twbs/bootstrap/pull/18258

一种选择是隐藏较小视口上的标题,这可以使用hidden-sm-down来完成。我发现的另一种解决方法是在图片上使用object-fit:cover,但旧浏览器不支持此功能。

.carousel-item > img {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  min-height: 32rem;
  object-fit: cover;
}

http://www.codeply.com/go/EaMgFMhff2