【问题标题】:How Can I Create a Full Screen Carousel/Slide Show?如何创建全屏轮播/幻灯片放映?
【发布时间】:2018-01-14 19:45:17
【问题描述】:

我是网页设计的初学者。我正在尝试为网页的特定部分创建全屏轮播/幻灯片。

更具体地说,我有一个这样的轮播: https://codepen.io/john9929/pen/aEjBqZ

<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.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Carousel Example</h2>
  <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">

      <div class="item active">
        <img src="https://www.lacity.org/sites/g/files/wph781/f/styles/tiled_homepage_blog/public/bigstock-Los-Angeles-5909078.jpg?itok=Pu2dewLz" alt="Los Angeles" style="width:100%;">
        <div class="carousel-caption">
          <h3>Los Angeles</h3>
          <p>LA is always so much fun!</p>
        </div>
      </div>

      <div class="item">
        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Chicago_skyline%2C_viewed_from_John_Hancock_Center.jpg/500px-Chicago_skyline%2C_viewed_from_John_Hancock_Center.jpg" alt="Chicago" style="width:100%;">
        <div class="carousel-caption">
          <h3>Chicago</h3>
          <p>Thank you, Chicago!</p>
        </div>
      </div>

      <div class="item">
        <img src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg" alt="New York" style="width:100%;">
        <div class="carousel-caption">
          <h3>New York</h3>
          <p>We love the Big Apple!</p>
        </div>
      </div>

    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>

</body>
</html>

我想把它变成这样: https://mobirise.com/bootstrap-carousel/

我该怎么做?

【问题讨论】:

  • 您在示例中使用的是 Bootstrap 3,但使用 Bootstrap 4 标记了这个问题。什么给出了?
  • 对错误感到抱歉。
  • 添加 bootstrap-3 标签。否则没有人会发现你的问题。
  • 我已经添加了标签。

标签: twitter-bootstrap-3 carousel


【解决方案1】:

将宽度设置为 100%,您甚至可以设置固定高度以保持一致性。

.carousel-inner img {
    width: 100%; /* Set width to 100% */
}

@media (min-width: 576px) { 
 .carousel-inner img {
  width: 100%; /* Set width to 100% */
  max-height:340px;
  }
}


@media (min-width: 768px) { 
  .carousel-inner img {
  width: 100%; /* Set width to 100% */
  max-height:720px;
  }
}


@media (min-width: 992px) { 
   .carousel-inner img {
  width: 100%; /* Set width to 100% */
  }
  .carousel-inner{
    max-height:580px;
  }
}


@media (min-width: 1200px) { 
    .carousel-inner img {
  width: 100%; /* Set width to 100% */
      max-height:700px;

  }
    .carousel-inner{
    max-height:700px;
  }

}
<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.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<body id="myPage" data-spy="scroll" data-target=".navbar" data-offset="50">


  <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://www.lacity.org/sites/g/files/wph781/f/styles/tiled_homepage_blog/public/bigstock-Los-Angeles-5909078.jpg?itok=Pu2dewLz" alt="LA" width="1200" height="700">
        <div class="carousel-caption">
          <h3>Los Angeles</h3>
          <p>LA is always so much fun!</p>
        </div>
      </div>

      <div class="item">
        <img src="https://media-cdn.tripadvisor.com/media/photo-s/0e/9a/e3/1d/freedom-tower.jpg" alt="New York" width="1200" height="700">
        <div class="carousel-caption">
          <h3>New York</h3>
          <p>Thank you, New York - A night we won't forget.</p>
        </div>
      </div>

      <div class="item">
        <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Chicago_skyline%2C_viewed_from_John_Hancock_Center.jpg/500px-Chicago_skyline%2C_viewed_from_John_Hancock_Center.jpg" alt="Los Angeles" width="1200" height="700">
        <div class="carousel-caption">
          <h3>Chicago</h3>
          <p>Thank you, Chicago!!</p>
        </div>
      </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>

【讨论】:

  • 谢谢。现在宽度为 100%。但是,我面临高度问题。当我包括“身高:80%;”在 .carousel-inner img 中,没有任何反应。如何降低图片的高度?
  • @john,应该使用媒体查询来完成。使用 % 将没有用,因为它仅在引用某些内容时才有效。我已经更新了答案,请检查,并会尽快添加简要说明。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-24
  • 1970-01-01
  • 2011-09-05
相关资源
最近更新 更多