Tutorial on how to create Bootstrap Carousel


<!DOCTYPE HTML>
<html> 
<head> 
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>
<!--   w  w  w .  j  a v a 2s.co  m-->
</head>
<body style='margin:20px;'>
 <script type='text/javascript'>
     $(document).ready(function () {
     if ($("[rel=popover]").length) {
         $("[rel=popover]").popover();
     }
   });
  </script>

<div class="bs-example">
      <div id="carousel-example-generic" class="carousel slide bs-docs-carousel-example">
        <ol class="carousel-indicators">
          <li data-target="#carousel-example-generic" data-slide-to="0" class=""></li>
          <li data-target="#carousel-example-generic" data-slide-to="1" class=""></li>
          <li data-target="#carousel-example-generic" data-slide-to="2" class="active"></li>
        </ol>
        <div class="carousel-inner">
          <div class="item">
            <img data-src="holder.js/900x500/auto/#777:#555/text:First slide" alt="First slide" src="http://java2s.com/style/download.png">
          </div>
          <div class="item">
            <img data-src="holder.js/900x500/auto/#666:#444/text:Second slide" alt="Second slide" src="http://java2s.com/style/download.png">
          </div>
          <div class="item active">
            <img data-src="holder.js/900x500/auto/#555:#333/text:Third slide" alt="Third slide" src="http://java2s.com/style/download.png">
          </div>
        </div>
        <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
          <span class="icon-prev"></span>
        </a>
        <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
          <span class="icon-next"></span>
        </a>
      </div>
    </div>

</body> 
</html>

Click to view the demo

Optional captions

We can add captions to slides with the <p> element within any .item. .carousel-caption places optional HTML within there and it will be automatically aligned and formatted.


<!DOCTYPE HTML>
<html> 
<head> 
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>
<!--   w w  w  . j av  a  2  s. co  m-->
</head>
<body style='margin:20px;'>

      <div id="carousel-example-captions" class="carousel slide bs-docs-carousel-example">
        <ol class="carousel-indicators">
          <li data-target="#carousel-example-captions" data-slide-to="0" class=""></li>
          <li data-target="#carousel-example-captions" data-slide-to="1" class=""></li>
          <li data-target="#carousel-example-captions" data-slide-to="2" class="active"></li>
        </ol>
        <div class="carousel-inner">
          <div class="item">
            <img data-src="holder.js/900x500/auto/#777:#777" alt="900x500" src="">
            <div class="carousel-caption">
              <h3>First slide label</h3>
              <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
            </div>
          </div>
          <div class="item">
            <img data-src="holder.js/900x500/auto/#666:#666" alt="900x500" src="">
            <div class="carousel-caption">
              <h3>Second slide label</h3>
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
            </div>
          </div>
          <div class="item active">
            <img data-src="holder.js/900x500/auto/#555:#5555" alt="900x500" src="">
            <div class="carousel-caption">
              <h3>Third slide label</h3>
              <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
            </div>
          </div>
        </div>
        <a class="left carousel-control" href="#carousel-example-captions" data-slide="prev">
          <span class="icon-prev"></span>
        </a>
        <a class="right carousel-control" href="#carousel-example-captions" data-slide="next">
          <span class="icon-next"></span>
        </a>
      </div>
    </div>
</body> 
</html>

Click to view the demo





















Home »
  Bootstrap »
    Bootstrap »




Introduction
Basic HTML Style
List
Table
Form
Layout
Navigation Bar
Button
Control