Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
191
rated 0 times [  193] [ 2]  / answers: 1 / hits: 20742  / 9 Years ago, wed, october 14, 2015, 12:00:00

I'm using the Slick Carousel, but there's one layout itch I can't scratch. When I have fewer items than the carousel can display at once, they're left-justified. I'd like them to be centered. For example, with slidesToShow equal 3 and only 2 items, I get



-------------------
IIIII IIIII
-------------------


when what I want is



-------------------
IIIII IIIII
-------------------


or if there's only 1 item:



-------------------
IIIII
-------------------


I've tried setting centerMode, but that's a completely different effect.



Is there a way to get the effect I want? It needs to handle slidesToShow being reduced by responsive breakpoints.


More From » carousel

 Answers
11

A quick inspection of the carousel's DOM shows that the items are put in an element with the class slick-track. It is possible to center the items by modifying the margins of that element:



.slick-track {
margin:auto;
}


Demo in this JSFiddle.



Note that the carousel in the demo sometimes stops working correctly when being resized while the last item is active but that happens regardless of this CSS modification.


[#64742] Monday, October 12, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianod

Total Points: 667
Total Questions: 106
Total Answers: 92

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
lucianod questions
;