Center slide items when they are less than the container width #614
-
|
I have 6 slide items in a single row and splide options are as below. {
"arrows": false,
"autoplay":true,
"height":"100px",
"type":"slide",
"pagination":false,
"perPage": 6,
"gap":20,
"breakpoints":{"768":{"perPage": 4},"576":{"perPage": 2}}
}According to my breakpoints, when it's 768 it will became 4 slide items |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
I can add |
Beta Was this translation helpful? Give feedback.
-
|
Edit: @ronaldaug I've found a solution. For this to work you need to know/calculate the total number of items you have at runtime. I'm guessing since you get your data from an API, you can work with something like HTML: <div class="wrapper">
<section class="splide">
<div class="splide__track">
<ul class="splide__list">
<li class="splide__slide"> -- Some loop renders multiple slides here. -- </li>
</ul>
</div>
</section>
</div>CSS: .wrapper {
display: flex;
justify-content: center;
}
.splide {
display: inline-block;
max-width: 100vw;
}Now for const slideStyle = `min-width: ${100/totalItems}%;`If you use a gap ( const slideStyle = `min-width: calc(${100/totalItems}% - ${gap} + ${gap} / ${totalItems});`So what's happening here:By giving the Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
|
You can use the overflow status checker: |
Beta Was this translation helpful? Give feedback.


Edit:
Meanwhile they updated the package, so see new answer in the comment below. 👍
@ronaldaug I've found a solution. For this to work you need to know/calculate the total number of items you have at runtime. I'm guessing since you get your data from an API, you can work with something like
items.length. I did this with react-splide but will try to tell the concept with the regular HTML.HTML:
CSS: