Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWL CAROUSEL fixed height?

I'm currently using Owl Carousel and am wondering if there's a way to adjust image sizes so that the height of each image is consistent. I'm using this plugin to display my photography, and I have both landscape and portrait sizes. I tried using autoWidth in the JS but it makes my portrait images too large and my landscape images too short, how do I get all the images to have a set height? I tried adjusting the CSS, but the landscape images seem to be behind the next image and doesn't display the full width. It looks like there is a set width, and when I adjust the width, the image just gets stretched. I have 19 items in the carousel. Also tried adjusting the items in the responsive part of the JS, when I adjust it to two items, the landscape images are the right proportions but the portrait images end up being stretched. Any ideas on how to fix?

Here's the CSS code I've used:

    #demos img{
    display: inline-block; 
    max-width: auto;  
    height: 500px!important; 
    margin-bottom: 30px;
  }

Javascript:

 $(document).ready(function() {
    $('.owl-carousel').owlCarousel({
      loop: true,
      margin: 0,
      responsiveClass: true,
      responsive: {
        0: {
          items: 1,
          nav: true
        },
        600: {
          items: 3,
          nav: false
        },
        1000: {
          items: 5,
          nav: true,
          loop: true,
          margin: 0
        }
      }
    })
  })
like image 773
abc0213 Avatar asked Dec 29 '16 00:12

abc0213


People also ask

How do you set the height of an owl carousel?

Setup. Add height to div="owl-wrapper-outer" so you can use diffrent heights on each slide. Use it only for one item per page setting.

How do I reduce the size of owl carousel?

I fixed it using max-width attribute and then setting the height to auto . Thanks for your reply.

How do you make an owl carousel responsive?

Setting of the responsive is very simple. Structure of responsive option: responsive : { // breakpoint from 0 up 0 : { option1 : value, option2 : value, ... }, // breakpoint from 480 up 480 : { option1 : value, option2 : value, ... }, // breakpoint from 768 up 768 : { option1 : value, option2 : value, ... } }


2 Answers

you can use this code in your css

   .owl-carousel .owl-stage {
      display: flex;
    }

   .owl-carousel .owl-item img {
      width: auto;
      height: 100%;
    }
like image 66
Nadim Al Abdou Avatar answered Sep 24 '22 04:09

Nadim Al Abdou


If you're using Bootstrap, then add the img-responsive class:

<img class="img-responsive">

This worked for me, I was also facing the same issue.

like image 37
JpG Avatar answered Sep 22 '22 04:09

JpG