简体   繁体   中英

How to center 2 slides in Slick carousel?

I use Slick in my project and I need to center two slides. Unfortunately centerMode option works only with odd numbered slidesToShow counts. I tried to center active slides by CSS but without effects.

Do you know any solution? Thank you in advance!


Edit:

Example of my carousel: https://jsfiddle.net/lukaszflorczak/y7t64oqs/ .

I want to have 1 centered item on the smallers screens, next 2, 3 etc. Not active slides have less opacity.

Slick Carousel center Mode with two slides is possible using variableWidth , you have to set width for each slide. After that you have to move slick-track half width of the slick slide.

Working fiddle here: Slick slide - two slides in center mode

Slick Carousel slides can be centered by setting the horizontal margins of .slick-track to auto in addition to using the centerMode attribute.

.slick-track {
  margin-left: auto;
  margin-right: auto
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM