Bootstrap > Carousel

Sliding image in Bootstrap

How to slide the image using carousel feature in Bootstrap


Sliding image

Bootstrap uses carousel to create sliding of the image

<style>
        .carousel-inner > .item > img,
        .carousel-inner > .item > a > img {
            width: 70%;
            margin: auto;
        }
    </style>
</head>
<body>
    <h2>Image sliding</h2>
    <div class="container">
        <br>
        <div id="myCarousel" class="carousel slide" data-ride="carousel">
            <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>
            </ol>
            <div class="carousel-inner">
                <div class="item active">
                    <img src="download.png" />                 
                </div>

                <div class="item">
                    <img src="download (1).png" />
                </div>

                <div class="item">
                    <img src="download2.jpg" />
                    
                </div>

                <div class="item">
                    <img src="download 3.jpg" />
                </div>

            </div>  
            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right" ></span>
                <span class="sr-only">Next</span> 
            </a>
        </div>
    </div>
  • In the above code snippet we have defined sliding an image using carousel, we have taken div with class attribute value as   container , we have taken another div with id as mycarousel with class attribute value carousel slide and data-ride as carousel, we have used style sheet to define the carousel-inner values to set margin and width 
  • In the next line we have value of class attribute carousel-indicators with ol elements as data-target as mycarousel  with data-slide as 0 to 3 and  data-slide ="0" is in active state
  • In the next line we are having div with value of  class attribute carousel-inner  to define the images to slide
  • In the next line we are having two anchor tags <a> tag to define the left carousel-control and right carousel-control  with href as #mycarousel, role as button  and data-slide=previous and next, the span with class attribute  glyphicon icons as chevron left and right     

output

 Views: 452 | Post Order: 43



Write for us