0

I'm trying to make a bootstrap carousel that contains 3 items at a time and has controls to switch to the next item. I created this carousel which does display the three items, the only problem is the controls aren't working when clicked, not quite sure what I'm missing.

I wrote a codepen with an example of my code here.

and my HTML below for quick referencing.

<div class="container">
  <div id="casesCarousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner">
      <div class="row">
        <div class="col-md-4">
          <div class="carousel-item active">
            <div class="card card-body">
              <h1>0</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item active">
            <div class="card card-body">
              <h1>1</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item active">
            <div class="card card-body">
              <h1>2</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>3</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>4</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>5</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>6</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>7</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>8</h1>
            </div>
          </div>
        </div>
      </div>
    </div>
    <a class="carousel-control-prev" href="#casesCarousel" role="button" data-slide="prev">
      <span class="carousel-control-prev-icon" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="carousel-control-next" href="#casesCarousel" role="button" data-slide="next">
      <span class="carousel-control-next-icon" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
 </div>

3 Answers3

1

You are missing here a link to the java script that enables the work of caroussel.

Add the following code to the header of your page

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

Then try again after refreshing ctrl+F5. Caroussel does not work on pure HTML and CSS it requres js libraries from bootstrap

Undry
  • 427
  • 2
  • 15
  • In the codepen I loaded these in and still no luck. – jermayne williams Aug 13 '20 at 07:24
  • Try it on your webserver better. Just include all the necessary libraries in the head tag. Then check for the errors in the Console (ctrl+shift+i in chrome). If you see errors there, show them here. – Undry Aug 13 '20 at 17:27
  • And check the access for to these scripts if you can open them from the machine where you test your site. – Undry Aug 13 '20 at 17:28
  • Its in the head. I have another carousel that only contains one item per slide that also has a different carousel ID and its working just fine. its also on the same page. – jermayne williams Aug 13 '20 at 19:34
0

This example you find have an error in codepen ;

bootstrap.min.js:6 Uncaught TypeError: Bootstrap's JavaScript requires jQuery. jQuery must @* be included before Bootstrap's JavaScript. at Object.jQueryDetection (bootstrap.min.js:6) at bootstrap.min.js:6 at bootstrap.min.js:6 at bootstrap.min.js:6 *@

the bootstrap JS source not added to files and become error when launch . please check your bootstrap JS existance and version to done this.

UnUsuAL
  • 74
  • 6
-1

have not noticed row and columnremove this. And visit bootstrap-carousel

and add jquery

Huzee
  • 114
  • 7