Bootstrap 4 carousel not working?

11,841

Solution 1

Works perfectly

<!DOCTYPE html>
<html lang="en">
<head>
  <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.3.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">
  <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.w3schools.com/bootstrap/ny.jpg" alt="Los Angeles" style="width:100%;">
      </div>

      <div class="item">
        <img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Chicago" style="width:100%;">
      </div>
    
      <div class="item">
        <img src="https://www.w3schools.com/bootstrap/newyork.jpg" alt="New york" style="width:100%;">
      </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>

Solution 2

Small mistake. class="carousel-item-active" should be class="carousel-item active". It is not a single class. You have combined the active class with carousel-item class. That is the mistake.

<div class="carousel-item-active">
  <img src="images/1.jpeg" alt="First-Slide">
</div>

Should changed to

<div class="carousel-item active">
  <img src="images/1.jpeg" alt="First-Slide">
</div>
Share:
11,841

Related videos on Youtube

Shahrukh Nasir
Author by

Shahrukh Nasir

Updated on June 04, 2022

Comments

  • Shahrukh Nasir
    Shahrukh Nasir almost 2 years

    I have the following BS4 Carousel code, (made it using this tutorial https://www.youtube.com/watch?v=n8ItscKLf7s&list=PLRtjMdoYXLf47brThg9-nTj8HSq8cQ0ND&index=53), However the code is not working, the first image is displayed but I dont know for what reasons carousel is not controlled and it does'nt go to the next image in any case. What is the possible solution?

    <div class="container">
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
                    <br />
                    <div id="carousel-example-generic" class="carousel-slide" data-ride="carousel">
                        <ol class="carousel-indicators">
                        <li data-target="#carousel-example-generic" data-slide-to="0" class="active"> </li>
                         <li data-target="#carousel-example-generic" data-slide-to="1"> </li>
                         <li data-target="#carousel-example-generic" data-slide-to="2"> </li>
                        </ol>
    
                        <div class="carousel-inner" role="listbox">
                            <div class="carousel-item-active">
                                <img src="images/1.jpeg" alt="First-Slide">
                            </div>
                            <div class="carousel-item">
                                <img src="images/2.jpeg" alt="Second-Slide">
                            </div>
                            <div class="carousel-item">
                                <img src="images/3.jpeg" alt="Third-Slide">
                            </div>
                        </div>
                        <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> 
                        <span class="icon-prev" aria-hidden="true"></span>
                        <span class="sr-only"> Previous </span>
                        </a>
                        <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> 
                        <span class="icon-next" aria-hidden="true"></span>
                        <span class="sr-only"> Next </span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    
    • AVI
      AVI about 6 years
    • Klooven
      Klooven about 6 years
      You should always check the documentation! Videos may be outdated as you can see in this case. getbootstrap.com is the URL for the official docs.
    • Suresh Ponnukalai
      Suresh Ponnukalai about 6 years
      @Shahrukh Nasir Answer you accepted using bootstrap 3.3.7, not sure which version you are looking.