gpt4 book ai didi

html - 如何使 Owl Carousel 中的图像居中

转载 作者:技术小花猫 更新时间:2023-10-29 12:12:30 25 4
gpt4 key购买 nike

My Owl Carousel 包含不同宽度和高度的图片。如何在中间对齐它们 - 水平和垂直?

$("#owl-example").owlCarousel({
navigation: true
});
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css">

<div id="owl-example" class="owl-carousel">
<div><img src="https://via.placeholder.com/120x120/69c/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/200x200/c69/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/160x160/9c6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/240x240/fc6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/160x160/9c6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/200x200/c69/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/120x120/69c/fff/" alt=""></div>
</div>

<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>

最佳答案

使用 owl carousel version 2.1.1 和 CSS3 Flexbox,只需添加样式:

.owl-carousel .owl-stage {
display: flex;
align-items: center;
}

查看代码片段:

$( document ).ready( function() {
$( '.owl-carousel' ).owlCarousel({
autoplay: true,
margin: 2,
loop: true,
responsive: {
0: {
items:1
},
200: {
items:3
},
500: {
items:4
}
}
});
});
.owl-carousel .owl-stage {
display: flex;
align-items: center;
}

.owl-carousel .caption {
text-align: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.min.css" rel="stylesheet"/>

<div class="owl-carousel">
<div class="item">
<img src="https://via.placeholder.com/350x200/?text=1">
<div class="caption">Caption 1</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/255x200/?text=2">
<div class="caption">Caption 2</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/627x200/?text=3">
<div class="caption">Caption 3</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/627x300/?text=4">
<div class="caption">Caption 4</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/627x400/?text=5">
<div class="caption">Caption 5</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/255x200/?text=6">
<div class="caption">Caption 6</div>
</div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script>

关于html - 如何使 Owl Carousel 中的图像居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39164738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com