gpt4 book ai didi

html - 如何在光滑的 slider 中垂直对齐图像

转载 作者:太空宇宙 更新时间:2023-11-04 06:15:22 27 4
gpt4 key购买 nike

我有一个光滑的 slider ,我想垂直对齐 a元素。我试过 vertical-align:middle;高度:100%;并尝试了更多,但我还没有找到解决方案。我也试过 <span class="helper"></span就像我在 this 中发现的那样stackoverflow 上的解决方案(jsfiddle)。我希望你们能帮助我。

我的 slider HTML 如下:

.slick-slide {
margin: 0px 20px;
}

.slick-slide img {
width: 100%;
}

.slick-slider
{
position: relative;
display: block;
box-sizing: border-box;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-touch-callout: none;
-khtml-user-select: none;
-ms-touch-action: pan-y;
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
}

.slick-list
{
position: relative;
display: block;
overflow: hidden;
margin: 0;
padding: 0;
}
.slick-list:focus
{
outline: none;
}
.slick-list.dragging
{
cursor: pointer;
cursor: hand;
}

.slick-slider .slick-track,
.slick-slider .slick-list
{
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
-o-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}

.slick-track
{
position: relative;
top: 0;
left: 0;
display: block;
}
.slick-track:before,
.slick-track:after
{
display: table;
content: '';
}
.slick-track:after
{
clear: both;
}
.slick-loading .slick-track
{
visibility: hidden;
}

.slick-slide
{
display: none;
float: left;
height: 100%;
min-height: 1px;
}
[dir='rtl'] .slick-slide
{
float: right;
}
.slick-slide img
{
display: block;
}
.slick-slide.slick-loading img
{
display: none;
}
.slick-slide.dragging img
{
pointer-events: none;
}
.slick-initialized .slick-slide
{
display: block;
}
.slick-loading .slick-slide
{
visibility: hidden;
}
.slick-vertical .slick-slide
{
display: block;
height: auto;
border: 1px solid transparent;
}
.slick-arrow.slick-hidden {
display: none;
}
<div class="container-fluid">
<h2 class="text-center text-secondary">Partners</h2>
<section class="customer-logos slider">
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2016/08/26/17/33/landscape-1622739_960_720.jpg"></a>
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2017/02/15/02/52/tree-2067496__340.jpg"></a>
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2016/08/26/17/33/landscape-1622739_960_720.jpg"></a>
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2017/02/15/02/52/tree-2067496__340.jpg"></a>
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2016/08/26/17/33/landscape-1622739_960_720.jpg"></a>
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2017/02/15/02/52/tree-2067496__340.jpg"></a>
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2016/08/26/17/33/landscape-1622739_960_720.jpg"></a>
<a href="#" target="_blank" class="slide"><img src="https://cdn.pixabay.com/photo/2017/02/15/02/52/tree-2067496__340.jpg"></a>
</section>
</div>

当然包括 jQuery 和 slick.js。可以看demo对here , 但带有方形图像。我的图像不是方形的,所以我需要垂直对齐水平 slider 中的图像。

提前致谢!

最佳答案

将此添加到您的 Jquery。如果您添加以下代码,它将解决您的问题。它为所有图像提供高度和位置。

$( ".slick-slide" ).each(function( index ) { 
$( this ).css('margin-top',
($('.slider').height()-$(this).height())/2+'px' );
});

关于html - 如何在光滑的 slider 中垂直对齐图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56019559/

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