html - 应用 CSS Grid 时 Owl Carousel 2 不工作
问题描述
我有一个运行良好的 Owl Carousel,它不在 CSS Grid 容器中。一旦我将它放在显示设置为网格的 HTML 标记中,它似乎不允许 Owl 正确显示,并且幻灯片会并排放置,并且看起来也会加倍。
我设置了一个小提琴,所以你可以明白我的意思。如果您删除网格 CSS 的注释,您将看到 Owl 将同时跨越所有幻灯片。
<section>
<article>
<div class="owl-carousel owl-theme">
<div class="slide"> Your Content </div>
<div class="slide"> Your Content </div>
<div class="slide"> Your Content </div>
<div class="slide"> Your Content </div>
<div class="slide"> Your Content </div>
<div class="slide"> Your Content </div>
<div class="slide"> Your Content </div>
</div>
section{
background-color: #000000;
/*display:grid;
grid-template-columns: repeat(1,1fr);
grid-template-areas: "slide-show";*/
article{
/*grid-area: slide-show;*/
.owl-carousel{
.slide{
background-color: red;
text-align: center;
color: #fff;
height: 500px;
}
}
}
}
$(document).ready(function(){
$('.owl-carousel').owlCarousel({
loop: true,
margin: 10,
nav: true,
dots: true,
autoHeight: true,
autoplay: false,
responsive: {
0: {
items: 1
},
768: {
items: 1
},
1400: {
items: 1
}
}
});
});
它似乎并排显示所有幻灯片,导致过多的水平滚动。我已经使用了很多这个库,但我想我从来没有尝试将它与 CSS Grid 结合起来。
解决方案
万一有人遇到这个问题。如果您将 CSS Grid 与 Owl Carousel 一起使用,则需要将父元素设置为min-width: 100%
.
推荐阅读
- c# - 无法将“System.Byte”类型的对象转换为“System.String”类型。
- android - 单击 TextInputLayout 后,应用在运行 5.1.1 的 Oppo F1S 中崩溃
- javascript - json 数组在键 javascript 中作为计数返回
- angular - 我应该使用什么包在 Angular 中创建图表?
- mongodb - MongoDB Compass 社区:数据库可见,但其集合在身份验证后未显示
- java - 检查您的模块类路径是否存在缺失或冲突的依赖项。无法访问 java.lang.Object
- javascript - ref 在反应式数组对象中不再反应式
- mariadb - brew install mariadb 失败,因为系统无法 chown for auth_pam_tool
- reactjs - 将 Photo Sphere Viewer 与 React 一起使用
- excel - 如何为每次另一列的值更改时重置的行提供数字?