0

enter image description hereI have a carousel on my page. I want its width to be 100%. Even after defining its width to 100% inside of a class, there is no effect on the Carousel. How can I make its width 100% and responsive as well?

Following is the class I have used to max it's width to 100%:-

.cwidth{

min-width: 100%;

}

and following is my Carousel code:-

<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 Answers2

1

Check libraries you've added, Try this working snippet,

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;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<div class="container fill">
  <div id="myCarousel" class="carousel slide">
    <div class="carousel-inner">
      <div class="active item">
        <div class="fill" style="background-image:url('//placehold.it/1024x700/449955/FFF');">
          <div class="container">

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

          </div>
        </div>
      </div>
      <div class="item">
        <div class="fill" style="background-image:url('//placehold.it/1024x700/CC1111/FFF');">
          <div class="container">

          </div>
        </div>
      </div>
    </div>
    <div class="pull-center">
      <a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
      <a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
    </div>
  </div>
</div>
codesayan
  • 1,705
  • 11
  • 22
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>
Payal2299
  • 148
  • 6