如何为轮播设置100%的宽度?

时间:2019-03-23 07:22:52

标签: css html5 twitter-bootstrap bootstrap-4 carousel

enter image description here我的页面上有一个轮播。我希望其宽度为100%。即使将其宽度定义为类内部的100%,也不会对轮播产生影响。我怎样才能使其宽度100%并具有响应能力?

以下是我用来使其宽度最大达到100%的类:-

.cwidth{

min-width: 100%;

}

以下是我的轮播代码:-

<div class="container">
  <h2>Carousel Example</h2>
  <div id="myCarousel" class="carousel slide cwidth" 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>
      <li data-target="#myCarousel" data-slide-to="4"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">

      <div class="item active">
        <img src="Images/LIB01.png" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="Images/LIB02.png" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="Images/LIB03.png" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="Images/LIB04.png" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="Images/LIB05.png" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</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>

2 个答案:

答案 0 :(得分:1)

检查您添加的库,尝试以下工作片段,

WKWebView
jQuery('.carousel').carousel();
html,
body {
  height: 100%;
}

.carousel,
.item,
.active {
  height: 100%;
}

.carousel-inner {
  height: 100%;
}

.fill {
  width: 100%;
  height: 100%;
  background-position: center;
  background-size: cover;
}

.container {
  width: 100% !important;
}


/* keep full widget on smaller screens */

@media (max-width: 767px) {
  body {
    padding-left: 0;
    padding-right: 0;
  }
}

答案 1 :(得分: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://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>

<div class="jumbotron">
  <h2>Carousel Example</h2>
  <div id="myCarousel" class="carousel slide cwidth" 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>
      <li data-target="#myCarousel" data-slide-to="4"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">

      <div class="item active">
        <img src="//placehold.it/1024x700" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="//placehold.it/1024x700/449955/FFF" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="//placehold.it/1024x700/CC1111/FFF" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="//placehold.it/1024x700/000000/FFF" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</p>
        </div>
      </div>

      <div class="item">
        <img src="//placehold.it/1024x700/CC3456/FFF" alt="LIB Image" style="width:100%;">
        <div class="carousel-caption">
          <h3>Some Text</h3>
          <p>Some Text</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>