I\'ve been using Bootstrap\'s carousel class and it has been straightforward so far, however one problem I\'ve had is that images of different heights cause the arrows to bo
This jQuery function worked best for me. I'm using bootstrap 4 within a WordPress theme and I've used the full jQuery instead of jQuery slim.
// Set all carousel items to the same height
function carouselNormalization() {
window.heights = [], //create empty array to store height values
window.tallest; //create variable to make note of the tallest slide
function normalizeHeights() {
jQuery('#latest-blog-posts .carousel-item').each(function() { //add heights to array
window.heights.push(jQuery(this).outerHeight());
});
window.tallest = Math.max.apply(null, window.heights); //cache largest value
jQuery('#latest-blog-posts .carousel-item').each(function() {
jQuery(this).css('min-height',tallest + 'px');
});
}
normalizeHeights();
jQuery(window).on('resize orientationchange', function () {
window.tallest = 0, window.heights.length = 0; //reset vars
jQuery('.sc_slides .item').each(function() {
jQuery(this).css('min-height','0'); //reset min-height
});
normalizeHeights(); //run it again
});
}
jQuery( document ).ready(function() {
carouselNormalization();
});
Source:
https://gist.github.com/mbacon40/eff3015fe96582806da5
Try this (I'm using SASS):
.carousel {
max-height: 700px;
overflow: hidden;
.item img {
width: 100%;
height: auto;
}
}
You can wrap the .carousel
into a .container
if you wish.