Bootstrap Carousel With Mobile Size
Solution 1:
So what I like to do with bootstrap carousels are give the item class a pading-bottom of a percentage instead of giving a height then play with this percentage untill you get the desired height. This will make them responsive and resize with the screen. Then instead of putting the image inside of the carousel give each carousel item another class like first-item, second-item, third-item and so forth. Then give this class a background image in your css. You can give the class of item a background-size:cover;
and a background position: center;
. Then instead of having an h1 tag in your carousel I like to just put a p tag and give it a class of carousel heading and then in your other p tag give it a class of carousel description. The reason I don't like to put h1 tags in the carousel is because there should be only one h1 tag on your page and you can specify that later but you if you want the h1 tag in the carousel just give it a class of carousel heading. The you can resize the text in these elements at samller screens in your css. So hopefully all of that made sense.
Check out this JSFiddle and drag the display window so you can see it resize- JSFiddle
Then here is your html and css:
Your Css:
#myCarousel.item{
padding-bottom: 50%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
min-height: 250px;
}
#myCarousel.first-item{
background-image: url('http://placehold.it/500x500');
}
#myCarousel.second-item{
background-image: url('http://placehold.it/500x500');
}
#myCarousel.third-item{
background-image: url('http://placehold.it/500x500');
}
#myCarousel.carousel-heading{font-size: 40px;}
@media screen and (max-width: 767px){
#myCarousel.carousel-heading{font-size: 18px;}
#myCarousel.carousel-description{font-size: 12px;}
#myCarousel.btn-primary{font-size: 14px;}
}
And Your Html:
<divid="myCarousel"class="carousel slide"data-ride="carousel"><!-- Indicators --><olclass="carousel-indicators"><lidata-target="#myCarousel"data-slide-to="0"class="active"></li><lidata-target="#myCarousel"data-slide-to="1"></li><lidata-target="#myCarousel"data-slide-to="2"></li></ol><divclass="carousel-inner"role="listbox"><divclass="item active first-item"><divclass="container"><divclass="carousel-caption"><pclass="carousel-heading">Example Heading</p><pclass="carousel-description">Note: If you're viewing this page via a <code>file://</code> URL, the "next" and "previous" Glyphicon buttons on the left and right might not load/display properly due to web browser security rules.</p><p><aclass="btn btn-lg btn-primary"href="#"role="button">Sign up today</a></p></div></div></div><divclass="item second-item"><divclass="container"><divclass="carousel-caption"><pclass="carousel-heading">Example Heading</p><pclass="carousel-description">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p><p><aclass="btn btn-lg btn-primary"href="#"role="button">Learn more</a></p></div></div></div><divclass="item third-item"><divclass="container"><divclass="carousel-caption"><pclass="carousel-heading">Example Heading</p><pclass="carousel-description">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p><p><aclass="btn btn-lg btn-primary"href="#"role="button">Browse gallery</a></p></div></div></div></div><aclass="left carousel-control"href="#myCarousel"role="button"data-slide="prev"><spanclass="glyphicon glyphicon-chevron-left"aria-hidden="true"></span><spanclass="sr-only">Previous</span></a><aclass="right carousel-control"href="#myCarousel"role="button"data-slide="next"><spanclass="glyphicon glyphicon-chevron-right"aria-hidden="true"></span><spanclass="sr-only">Next</span></a></div><!-- /.carousel -->
Post a Comment for "Bootstrap Carousel With Mobile Size"