Bootstrap image carousel
Go to solution
Solved by elcou96,
nvm found a way:
The solution I used:
I put the image as the background of a div with a fixed heigth and made sure the image was positioned correctly.
new html:
<!-- Carousel ================================================== --> <div id="carousel" class="carousel slide" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#carousel" data-slide-to="0" class="active"></li> <li data-target="#carousel" data-slide-to="1"></li> <li data-target="#carousel" data-slide-to="2"></li> </ol> <div class="carousel-inner" role="listbox"> <div class="item active"> <div class="carousel_image" style="background: url(images/lunchbox.jpg) no-repeat"></div> <!--<img class="first-slide img-responsive center-block" src="images/sample.jpg" alt="First slide">--> <div class="container"> <div class="carousel-caption"> <p> <a href="#"><h2>The Lunchbox</h2></a> <h6>8/01 - 20u</h6> </p> </div> </div> </div> <div class="item"> <div class="carousel_image" style="background: url(images/lunchbox.jpg) no-repeat"></div> <!--<img class="second-slide img-responsive center-block" src="images/sample2.png" alt="Second slide">--> <div class="container"> <div class="carousel-caption"> <p> <a href="#"><h2>The Lunchbox</h2></a> <h6>8/01 - 20u</h6> </p> </div> </div> </div> <div class="item"> <div class="carousel_image" style="background: url(images/lunchbox.jpg) no-repeat"></div> <!--<img class="third-slide img-responsive center-block" src="images/sample.jpg" alt="Third slide">--> <div class="container"> <div class="carousel-caption"> <p> <a href="#"><h2>The Lunchbox</h2></a> <h6>8/01 - 20u</h6> </p> </div> </div> </div> </div> </div><!-- /.carousel -->
Using @media, I made a different style for small devices.
added this to my css:
.carousel .carousel_image { background-size: contain !important; width: 100%; height: 400px; background-position: center !important; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } @media (max-width:499px){ .carousel .carousel_image { background-size:contain !important; background-position: center !important; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; width: 100%; height: 200px; } }
The solution isn't 100% as I wanted, but it works
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now