简体   繁体   中英

Slick slider empty space with fluid background image

I'm using Slick slider to show some fuid background images, but each new image added ("slide-img" class), a empty space is added on top and bottom of the slider.

I think that the padding-top is causing this some way, but i don't know how to fix it maintaining the fluid effect, i would be grateful if someone knows.

Here is the JSFiddle

 $('.slides').slick({ slidesToShow: 1, autoplay: true, }); 
 .slide-img { background: url('http://i.imgur.com/RVfIr7W.jpg') no-repeat center / 100%; padding-top: 36.59%; } 
 <link href="https://cdn.jsdelivr.net/jquery.slick/1.6.0/slick.css" rel="stylesheet"/> <div class="slides"> <div class="slide-img"></div> <div class="slide-img"></div> <div class="slide-img"></div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/jquery.slick/1.6.0/slick.min.js"></script> 

Slick creates a wrapper for the slides and puts them side by side, so when you use padding on the slide itself it will calculate the percentage based on the width of all the slides put together.

You need to add an internal div to put the padding on, this way it takes the percentage of a single slide and you will get the height you are looking for.

  <div class="slides">
    <div><div class="slide-img"></div></div>
    <div><div class="slide-img"></div></div>
    <div><div class="slide-img"></div></div>
  </div>

https://jsfiddle.net/ke51vqqm/3/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM