bootstrap 图像滑块不同的图像大小

bootstrap image slider different image size

我有一些使用 bootstrap 的经验,我想使用以下方法创建图像滑块:

http://www.w3schools.com/bootstrap/bootstrap_carousel.asp

https://startbootstrap.com/template-overviews/business-casual/

示例一切正常。如果我想使用不同大小的图像,就会出现问题:

我找到了许多类似的主题,但 none 对我有用。

是否可以有固定的比例 - 不过是照片尺寸?仅使用 css?

拉伸图像甚至 "croping" 图像

代码

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
  .carousel-inner > .item > img,
  .carousel-inner > .item > a > img {
      width: 70%;
      margin: auto;
  }
  </style>
</head>
<body>

<div class="container">
  <br>
  <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>
      <li data-target="#myCarousel" data-slide-to="3"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="img_chania.jpg" alt="Chania" width="460" height="345">
      </div>

      <div class="item">
        <img src="img_chania2.jpg" alt="Chania" width="460" height="345">
      </div>

      <div class="item">
        <img src="img_flower.jpg" alt="Flower" width="460" height="345">
      </div>

      <div class="item">
        <img src="img_flower2.jpg" alt="Flower" width="460" height="345">
      </div>
    </div>

    <!-- Left and right controls -->
    <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>
</div>

</body>
</html>

对于某些网站,我不得不针对此类问题采取一些技巧。

我只是把img标签去掉,设置为项目背景。

Bootply : http://www.bootply.com/AVNXeL4Jtw

HTML:

 <div class="carousel-inner" role="listbox">
      <div class="item active" style="background-image: url(//placehold.it/1024x700)  ">
      </div>

      <div class="item" style="background-image: url(//placehold.it/100x100)  ">
      </div>

      <div class="item" style="background-image: url(//placehold.it/1024x700)  ">
      </div>

      <div class="item" style="background-image: url(//placehold.it/200x200)  ">
      </div>
    </div>

CSS:

.carousel-inner .item{ 
   height:500px; 
   background-size:cover;
   background-position: center center;
}