1.

How to create a carousel in Bootstrap?

Answer»

For CAROUSEL controls, we need an id. Here, we have:

id="newCarousel"

The following sets the <div> has a carousel:

class="carousel slide"

The data-ride="carousel" attribute begins animating the carousel when the page loads.

The bottom of each slide has dots that indicates which slide you’re watching right now. The class .carousel-indicators specify it:

<ol class="carousel-indicators">     <li data-target="#newCarousel" data-slide-to="0" class="active"></li>     <li data-target="#newCarousel" data-slide-to="1"></li>     <li data-target="#newCarousel" data-slide-to="2"></li> </ol>

The slides are set with class .carousel-inner. We have set the next and previous controls as well with the data-slide attribute:

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

The following is an example:

<!DOCTYPE html> <html lang="en"> <head>   <title>Bootstrap Carousel</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.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">   <h2>KnowledgeHut Blog</h2>     <div id="newCarousel" class="carousel slide" data-ride="carousel">     <!-- Indicators -->     <ol class="carousel-indicators">       <li data-target="#newCarousel" data-slide-to="0" class="active"></li>       <li data-target="#newCarousel" data-slide-to="1"></li>       <li data-target="#newCarousel" data-slide-to="2"></li>     </ol>     <div class="carousel-inner">       <div class="ITEM active">         <img src="https://d2o2utebsixu4k.cloudfront.net/media/images/599e46ac-60e1-429b-a305-e02574081e3c.jpg" alt="How To Pass Leading SAFe® 4 Exam" style="width:100%;">       </div>       <div class="item">         <img src="https://d2o2utebsixu4k.cloudfront.net/media/images/079f81ac-d7f7-4c0c-8919-46cc1602c950.jpg" alt="Top-paying AGILE Certifications To Consider In 2018" style="width:100%;">       </div>       <div class="item">         <img src="https://d2o2utebsixu4k.cloudfront.net/media/images/4096881a-05ea-4162-96cf-3e7949ea82a7.jpg" alt="DevOps In 5 letters: Should We Say CALMS or CALMR?" style="width:100%;">       </div>     </div>     <!--controls -->     <a class="left carousel-control" href="#newCarousel" data-slide="prev">       <span class="glyphicon glyphicon-chevron-left"></span>       <span class="sr-only">Previous</span>     </a>     <a class="right carousel-control" href="#newCarousel" data-slide="next">       <span class="glyphicon glyphicon-chevron-right"></span>       <span class="sr-only">Next</span>     </a>   </div> </div> </body> </html>

The output: Next slide in the carousel: 



Discussion

No Comment Found