Swiper JS slides per view and slides per column displaying incorrectly

Joy Dey picture Joy Dey · Mar 21, 2020 · Viewed 7.1k times · Source

I was trying to make a 2 rows of slides on bootstrap using swiper js using the demo given at the official page. However When I copied the code and ran on my browser it displayed like thisenter image description here

The code is exactly the same as the demo page

 <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Swiper demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">

     <link rel="stylesheet" href="../package/css/swiper.min.css">
     <style>

      .swiper-container {
      width: 100%;
      height: 100%;
      margin-left: auto;
      margin-right: auto;
     }
     .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;
      height: calc((100% - 30px) / 2);

      /* Center slide text vertically */
      display: -webkit-box;
      display: -ms-flexbox;
      display: -webkit-flex;
      display: flex;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      -webkit-justify-content: center;
      justify-content: center;
      -webkit-box-align: center;
      -ms-flex-align: center;
      -webkit-align-items: center;
      align-items: center;
    }
  </style>
    </head>
    <body>
      <div class="swiper-container">
        <div class="swiper-wrapper">
        <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div>
        <div class="swiper-slide">Slide 3</div>
      <div class="swiper-slide">Slide 4</div>
      <div class="swiper-slide">Slide 5</div>
      <div class="swiper-slide">Slide 6</div>
      <div class="swiper-slide">Slide 7</div>
      <div class="swiper-slide">Slide 8</div>
      <div class="swiper-slide">Slide 9</div>
      <div class="swiper-slide">Slide 10</div>
      </div>
      <div class="swiper-pagination"></div>
     </div>

     <script src="../package/js/swiper.min.js"></script>

     <script>
      var swiper = new Swiper('.swiper-container', {
      slidesPerView: 3,
      slidesPerColumn: 2,
      spaceBetween: 30,
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
      },
    });
  </script>
</body>
</html>

I tried changing the slides per view and slides per column but those were almost the same.

Answer

kr1571n picture kr1571n · Dec 28, 2020

I had the same problem. It seems that the setting slidesPerColumn does not work. Then I was checking which CSS comes from the swiper css with those Swiper Slide settings:

.swiper-container-multirow-column > .swiper-wrapper {
   flex-direction: column;
 }

It turned out that when i overwrite the CSS, it works:

.swiper-container-multirow-column > .swiper-wrapper {
  flex-direction: inherit;
}

Or instead, add the following setting:

slidesPerColumnFill: 'row'

I hope that helps (even if it is a late answer on this topic).