我已阅读文档并在 Google 上搜索过 - 找不到答案。我有一个视差引导幻灯片。在第一张幻灯片中,我试图让 3 个 div 列的高度和宽度相等,并排排列在一行中。代码如下。但是,渲染时,每列都堆叠在一起,因此基本上只有 1 列。请帮忙?
<div style="--swiper-navigation-color: #fff; --swiper-pagination-color: #fff" class="swiper mySwiper">
<div class="parallax-bg" style="
background-image: url(https:// domain .com/assets/img/moonscape.jpg);
" data-swiper-parallax="-23%"></div>
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="title" data-swiper-parallax="-300">Slide 1</div>
<div class="subtitle" data-swiper-parallax="-200">Subtitle</div>
<div class="text" data-swiper-parallax="-100">
<div class="container">
<div class="row">
<div class="col-sm-4">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
dictum mattis velit, sit amet faucibus felis iaculis nec. Nulla
laoreet justo vitae porttitor porttitor. Suspendisse in sem justo.
Integer laoreet magna nec elit suscipit, ac laoreet nibh euismod.
Aliquam hendrerit lorem at elit facilisis rutrum. Ut at
ullamcorper velit. Nulla ligula nisi, imperdiet ut lacinia nec,
tincidunt ut libero. Aenean feugiat non eros quis feugiat.
</p>
</div>
<div class="col-sm-4">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
dictum mattis velit, sit amet faucibus felis iaculis nec. Nulla
laoreet justo vitae porttitor porttitor. Suspendisse in sem justo.
Integer laoreet magna nec elit suscipit, ac laoreet nibh euismod.
Aliquam hendrerit lorem at elit facilisis rutrum. Ut at
ullamcorper velit. Nulla ligula nisi, imperdiet ut lacinia nec,
tincidunt ut libero. Aenean feugiat non eros quis feugiat.
</p>
</div>
<div class="col-sm-4">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
dictum mattis velit, sit amet faucibus felis iaculis nec. Nulla
laoreet justo vitae porttitor porttitor. Suspendisse in sem justo.
Integer laoreet magna nec elit suscipit, ac laoreet nibh euismod.
Aliquam hendrerit lorem at elit facilisis rutrum. Ut at
ullamcorper velit. Nulla ligula nisi, imperdiet ut lacinia nec,
tincidunt ut libero. Aenean feugiat non eros quis feugiat.
</p>
</div>
</div>
</div>
</div>
</div>
<div class="swiper-slide">
<div class="title" data-swiper-parallax="-300">Slide 2</div>
<div class="subtitle" data-swiper-parallax="-200">Subtitle</div>
<div class="text" data-swiper-parallax="-100">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
dictum mattis velit, sit amet faucibus felis iaculis nec. Nulla
laoreet justo vitae porttitor porttitor. Suspendisse in sem justo.
Integer laoreet magna nec elit suscipit, ac laoreet nibh euismod.
Aliquam hendrerit lorem at elit facilisis rutrum. Ut at
ullamcorper velit. Nulla ligula nisi, imperdiet ut lacinia nec,
tincidunt ut libero. Aenean feugiat non eros quis feugiat.
</p>
</div>
</div>
<div class="swiper-slide">
<div class="title" data-swiper-parallax="-300">Slide 3</div>
<div class="subtitle" data-swiper-parallax="-200">Subtitle</div>
<div class="text" data-swiper-parallax="-100">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
dictum mattis velit, sit amet faucibus felis iaculis nec. Nulla
laoreet justo vitae porttitor porttitor. Suspendisse in sem justo.
Integer laoreet magna nec elit suscipit, ac laoreet nibh euismod.
Aliquam hendrerit lorem at elit facilisis rutrum. Ut at
ullamcorper velit. Nulla ligula nisi, imperdiet ut lacinia nec,
tincidunt ut libero. Aenean feugiat non eros quis feugiat.
</p>
</div>
</div>
<div class="swiper-slide">
<div class="title" data-swiper-parallax="-300">Slide 4</div>
<div class="subtitle" data-swiper-parallax="-200">Subtitle</div>
<div class="text" data-swiper-parallax="-100">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
dictum mattis velit, sit amet faucibus felis iaculis nec. Nulla
laoreet justo vitae porttitor porttitor. Suspendisse in sem justo.
Integer laoreet magna nec elit suscipit, ac laoreet nibh euismod.
Aliquam hendrerit lorem at elit facilisis rutrum. Ut at
ullamcorper velit. Nulla ligula nisi, imperdiet ut lacinia nec,
tincidunt ut libero. Aenean feugiat non eros quis feugiat.
</p>
</div>
</div>
</div>
<div class="swiper-button-next"></div>
<div class="swiper-button-prev"></div>
<div class="swiper-pagination"></div>
</div>
您确定您正确导入/使用了 Bootstrap 5 吗?我使用 Bootstrap 5 测试了您的 HTML,行正确呈现了三列。使用 Bootstrap 3 测试您的 HTML 时,我得到了您描述的结果(所有列都堆叠在一起)。
这是我制作的codepen,它显示了正确导入 Bootstrap 5 时 HTML 的工作情况
如果您正在使用 CDN,请尝试将其交换为:
或者,您也可以只添加
display: flex
行类。如果您需要有关开始使用 Bootstrap 5 的更多信息,请访问此链接。
你必须正确检查你的 CSS 或 bootstrap,如下所示:
CSS
<link rel="stylesheet" href="mystyle.css">
引导程序
<linkhref="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">