css Swiper.js幻灯片宽度

slsn1g29  于 2023-03-05  发布在  其他
关注(0)|答案(3)|浏览(137)

Swiper.js存在一个大问题

有没有可能以某种方式使幻灯片的宽度再次等于内容的宽度?
此时,所有幻灯片都拉伸到父幻灯片的全宽,很可能是因为我设置了容器网格元素
我一直试图解决这个问题很长一段时间,但我只是不能告诉我,我会感激!!!
(随附屏幕截图)enter image description here

pvcm50d1

pvcm50d11#

flex-shrink: 100 !important;
width: **set according to your design**;

真管用!

wnavrhmk

wnavrhmk2#

据我所知,没有一个标准的方法可以使幻灯片的宽度等于内容的宽度。但是,您可以在CSS文件中手动指定每张幻灯片的宽度,如下所示:

    • 超文本标记语言:**
<!-- Slider main container -->
<div class="swiper">
  <!-- Additional required wrapper -->
  <div class="swiper-wrapper">
    <!-- Slides -->
    <div class="swiper-slide">Slide 1</div>
    <div class="swiper-slide">Slide 2</div>
    <div class="swiper-slide">Slide 3</div>
    ...
  </div>
  <!-- If we need pagination -->
  <div class="swiper-pagination"></div>

  <!-- If we need navigation buttons -->
  <div class="swiper-button-prev"></div>
  <div class="swiper-button-next"></div>

  <!-- If we need scrollbar -->
  <div class="swiper-scrollbar"></div>
</div>
    • 中央支助组:**
.swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
}

.swiper-slide img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.swiper-slide {
    width: 50%;
}

.swiper-slide:nth-child(2n) {
    width: 20%;
}

.swiper-slide:nth-child(3n) {
    width: 40%;
}

同时在CSS文件中导入以下两行代码:

swiper/css
swiper/css/bundle
    • 联属萨摩亚**
const swiper = new Swiper('.swiper', {
  speed: 400,
  spaceBetween: 100,
});
e1xvtsh3

e1xvtsh33#

幻灯片每视图:"自动"
和CSS中。swiper-slide {宽度:适合含量}

相关问题