光滑滑块无法在Flex容器中工作

时间:2017-08-30 14:14:20

标签: javascript html css flexbox slick.js

我正试图在一个列中垂直居中一个光滑的轮播( http://kenwheeler.github.io/slick/ )。所以我在列(光滑滑块的容器)上使用display: flex; align-items: center;但它会打破滑块。

所以我尝试将旋转木马放在一个绝对位置或使用flexbox,但它们都打破了光滑的滑块。

我希望有人能为这个问题找到一个css / js / jquery解决方案:)

这是问题的一小部分:https://jsfiddle.net/victor_allegret/g3dsd78w/

(抱歉,我在向堆栈溢出代码段添加光滑时遇到问题)

HTML:

<div class='flex-container'>

 <div class='single-item'>

  <div><h3>1</h3></div>
  <div><h3>2</h3></div>
  <div><h3>3</h3></div>
  <div><h3>4</h3></div>
  <div><h3>5</h3></div>
  <div><h3>6</h3></div>

 </div>

</div>

CSS:

.flex-container {
 /* Using flexbox */
 display: flex;
 align-items: center;
 /*----*/
 margin: 0 auto;
 padding: 40px;
 height: 500px;
 width: 80%;
 color: #333;
 background: #419be0;
}

.slick-slide {
 text-align: center;
 color: #419be0;
 background: white;
}

JS:

$(".single-item").slick({
 dots: true
});

1 个答案:

答案 0 :(得分:2)

喜欢这个? With absolute position.

RewriteEngine On
RewriteRule ^createRoom/?$ /createRoom.php [NC,L]
RewriteRule ^deleteRoom/([a-z0-9-]+)/?$ /deleteRoom.php?session=$1 [NC,L]

And this with FlexBox.

.abs-container {
  position:absolute;

  height:140px;
  width:300px;
  top:50%;
  left:50%;
  margin:-70px 0 0 -150px;

  color: #333;
  background: #419be0;
}

<强> HTML

.flex-container {
    position:absolute;
    top:0px;
    bottom:0px;
    width:100%;
    height:100%;

  /* Using flexbox */
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    align-content: stretch;
    align-items: center;
  /*----*/

  color: #333;
  background: #419be0;
}
.flex-child {
    width: 300px;
    order: 0;
    flex: 0 1 auto;
    align-self: center;
}