我正试图让boostrap旋转木马在浏览器窗口的右侧完全显示出来。
为此,应修改旋转木马的边距,使图像保持在右侧中心的最大宽度(页面的5/12)或最大高度(浏览器窗口的高度),具体取决于图像纵横比。
下面是我想要得到的一个例子:
jquery - 引导轮播会完全显示浏览器窗口的右侧-LMLPHP
这里有一个关于它当前工作方式的小提琴:https://jsfiddle.net/v71c8udo/7/
下面是当前的HTML代码:

<!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://bootswatch.com/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <style>
      .carousel-inner > .item > img,
      .carousel-inner > .item > a > img {
        width: 100%;
        height: 100%;
        margin: auto;
      }
    </style>
  </head>
  <body>
    <div class="navbar navbar-default navbar-fixed-top ">
      <div class="container">
        <div class="navbar-header">
          <a href="#" class="navbar-brand">website</a>
          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
            <span class="icon-bar"></span>
          </button>
        </div>
      </div>
    </div>
    <div class="col-sm-offset-7 col-sm-5" style="margin-right:0px;padding-right:0px; height:100vh;">
      <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>
        </ol>

        <!-- Wrapper for slides -->
        <div class="carousel-inner" role="listbox">
          <div class="item active">
            <img src="https://culturieuse.files.wordpress.com/2015/02/arearea_by_paul_gauguin-joyfulness-1892.jpg" alt="Chania">
          </div>

          <div class="item">
            <img src="http://uploads2.wikiart.org/images/paul-gauguin/road-in-tahiti-1891.jpg" alt="Chania">
          </div>

          <div class="item">
            <img src="http://www.leboismiroir.fr/wp-content/uploads/Pld-Gauguin.jpg" alt="Flower">
          </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>
    </div>
  </body>
</html>

最佳答案

.carousel, .carousel-inner, .carousel-inner > .item{
  height:100%;
  }

body .carousel-inner > .item > img{
  height: auto;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  }

<!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://bootswatch.com/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <style>
      .carousel-inner > .item > img,
      .carousel-inner > .item > a > img {
        width: 100%;
        height: 100%;
        margin: auto;
      }
    </style>
  </head>
  <body>
    <div class="navbar navbar-default navbar-fixed-top ">
      <div class="container">
        <div class="navbar-header">
          <a href="#" class="navbar-brand">website</a>
          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
            <span class="icon-bar"></span>
          </button>
        </div>
      </div>
    </div>
    <div class="col-sm-offset-7 col-sm-5" style="margin-right:0px;padding-right:0px; height:100vh;">
      <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>
        </ol>

        <!-- Wrapper for slides -->
        <div class="carousel-inner" role="listbox">
          <div class="item active">
            <img src="https://culturieuse.files.wordpress.com/2015/02/arearea_by_paul_gauguin-joyfulness-1892.jpg" alt="Chania">
          </div>

          <div class="item">
            <img src="http://uploads2.wikiart.org/images/paul-gauguin/road-in-tahiti-1891.jpg" alt="Chania">
          </div>

          <div class="item">
            <img src="http://www.leboismiroir.fr/wp-content/uploads/Pld-Gauguin.jpg" alt="Flower">
          </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>
    </div>
  </body>
</html>

10-05 23:12