Search code examples
javascriptjqueryhtmlcssowl-carousel

Center align owl carousel items


How can I align this owl items in the middle of the screen?

Tried: center: true

Please see in full page view:

var owl = $('.video-thumb').owlCarousel({
  items: 7,
  autoplay: false,
  loop: false,
  nav: true,
  dots: false,
  margin: 30,
  center: true,
  responsive: {
    0: {
      items: 1
    },
    640: {
      items: 2
    },
    768: {
      items: 3
    },
    992: {
      items: 4
    },
    1200: {
      items: 5
    },
    1600: {
      items: 7
    }
  }
});
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet"/>
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css" rel="stylesheet"/>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/vendors/jquery.min.js"></script>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>
<div class="video-thumb owl-carousel owl-theme">
  <div class="thumb-item">
    <a href="#"><img src="https://via.placeholder.com/150" alt="eMAM Cloud" /></a>
  </div>
  <div class="thumb-item">
    <a href="#"><img src="https://via.placeholder.com/150" alt="eMAM Cloud" /></a>
  </div>
</div>

It may contains any number of items.

JSFiddle


Solution

  • Add this to your CSS:

    .owl-carousel {
        display: flex !important; /* To override display:block I added !important */
        flex-direction: row;
        justify-content: center; /* To center the carousel */
    }
    

    JSFiddle : https://jsfiddle.net/2z1qadv3/