Move Swiper Pagination to Top of Swiper Container
Asked Answered
G

8

10

I would like to move the pagination bullets to the top of the viewing area, from the bottom.

<div class="swiper-container">
    <div class="swiper-wrapper"></div>
    <div class="swiper-pagination"></div>
</div>

Currently, the pagination bullets show below all wrapper or JavaScript appended slide content. I would like it to appear above that.

More info: https://framework7.io/docs/swiper.html#default-swiper-with-pagination

Gingras answered 22/3, 2017 at 21:12 Comment(0)
A
12

only add padding bottom on swipper-wrapper and remove bottom on pagination

html

<div class="swiper-container">
    <div class="swiper-wrapper"></div>
    <div class="swiper-pagination"></div>
</div>

css

.swiper-wrapper{
    padding-bottom: 30px;
}

.swiper-container-horizontal>.swiper-pagination-bullets, .swiper-pagination-custom, .swiper-pagination-fraction{
    bottom: 0px !important;
}

solved

Anthology answered 13/6, 2020 at 3:33 Comment(0)
I
4

This worked better for me, as my slides are of uneven size:

.swiper-pagination {
    top: 2px;
}
Idona answered 3/1, 2020 at 21:59 Comment(0)
G
3

Figured it out - fairly simple, but I don't know my CSS yet.

.swiper-pagination {
    bottom: 95%;
}

Modify the bottom or top properties.

Gingras answered 24/3, 2017 at 21:37 Comment(1)
This works for me, I am not sure why messing with the top: 2px will cause the entire slider to fail.Esperance
H
3

Try this:

  1. open swiper>modules>pagination>pagination.less

  2. at the top line where the :root {...} sits, uncomment the line --swiper-pagination-bottom and --swiper-pagination-top

  3. edit the value of those variables to the following

:root {
        --swiper-pagination-bottom: auto;
        --swiper-pagination-top: 8px;
}

If you use CDN to import the module,

  1. add the code above as option parameter as below
const params = {
injectStyles: [`
    :root {
        --swiper-pagination-bottom: auto;
        --swiper-pagination-top: 8px;
    }
...
}
  1. initialize the swiper - complete main javascript file code may look something like this
const swiperEl = document.querySelector('swiper-container')

const params = {
    injectStyles: [`
    :root {
        --swiper-pagination-bottom: auto;
        --swiper-pagination-top: 8px;
    }

    ...
      `],

    pagination: {
        clickable: true,
        renderBullet: function (index, className) {
            return '<span class="' + className + '">' + (index + 1) + "</span>";
        },
    },
}

Object.assign(swiperEl, params)

swiperEl.initialize();

....

Hope it works on your side!

Hafiz answered 15/3, 2023 at 9:17 Comment(0)
S
1
swiper-container {
  --swiper-pagination-bottom: 20px;
}
Syncrisis answered 2/6, 2023 at 4:43 Comment(0)
Z
0

html

<div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide"></div>
        <div class="swiper-slide"></div>
        <div class="swiper-slide"></div>
    </div>
    <div class="swiper-pagination"></div>
</div>

If you're using https://www.npmjs.com/package/ngx-swiper-wrapper with angular and if one of your div.swiper-slide has a different height, it's better to use this property :

css

.swiper-pagination {
    bottom: calc(100% - 2rem);
}

For some reasons, when I tried to use the top css property on .swiper-pagination class, it disabled click event inside the div.swiper-slide with ngx-swiper-wrapper.

Zoologist answered 1/8, 2021 at 17:42 Comment(0)
L
0

not sure if this will be helpful to anyone, but I was able to do this by just styling the Swiper container w/ flex / flex-direction: column;, then I just re ordered the pagination stuff by setting it's order to order: -1;

Lax answered 8/8, 2022 at 7:31 Comment(0)
B
0

For Swiper Element in an project using SCSS this can be done by overriding the CSS variable. For example, in my Angular Ionic project

:host {
    --swiper-pagination-top: 2px;
}
Bacterin answered 29/2 at 20:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.