I'm using bxslider script to build a carousel. I can do everything fine, I'm just having a problem trying to align to center the slides vertically, as they don't have the same height. I've tried numerous align techniques, but all seem to fail when the bxslider is in action. Here's a jsfiddle example.
Currently in the example I've set a very simple CSS rule that works when the carousel is not set:
.bxslider-inner {
vertical-align: middle;
display: inline-block;
}
But, as you can see in the jsfiddle, when the carousel is active, the vertical alignment doesn't work anymore.
I'm starting to suspect I might have to change the core code of the script to achieve this.
You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.
To center both vertically and horizontally, use padding and text-align: center : I am vertically and horizontally centered.
One way to vertically center is to use my-auto . This will center the element within it's flexbox container (The Bootstrap 4 . row is display:flex ). For example, h-100 makes the row full height, and my-auto will vertically center the col-sm-12 column.
Update your CSS like this. The key is not float
ing the element because you are always making it inline-block
.bxslider-inner {
vertical-align: middle;
display: inline-block;
float: none !important;
}
One more thing... To make it match your example, change slideMargin:20
to slideMargin:10
after you have done the float: none !important;
Fiddle: http://jsfiddle.net/sSqAx/9/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With