Slick Slider - Box Shadows are cut off
Asked Answered
K

4

19

The problem is that the slick slider div has overflow: hidden; so the box-shadows of the slides divs keep getting cut off.

Anybody ran into this problem too?

Here is a little fiddle demonstrating the problem: https://jsfiddle.net/2zvcud0u/

HTML

  <div class="slider row">
    <div class="col-sm-4">
      <div class="drop-shadow">
        <div class="content">
          <p>Lorem ipsum dolor sit amet</p>
        </div>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="drop-shadow">
        <div class="content">
          <p>Lorem ipsum dolor sit amet</p>
        </div>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="drop-shadow">
        <div class="content">
          <p>Lorem ipsum dolor sit amet</p>
        </div>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="drop-shadow">
        <div class="content">
          <p>Lorem ipsum dolor sit amet</p>
        </div>
      </div>
    </div>
  </div>
</div>

CSS

.row{
  margin: 20px 0;
}

.drop-shadow {
  box-shadow: 0px 0px 43px 0px rgba(0, 0, 0, 0.35);
}

.content{
  margin: 10px;
}

JS

$('.slider').slick({
  autoplay: false,
  dots: false,
  arrows: false,
  infinite: false,
  speed: 300,
  slidesToShow: 3,
  slidesToScroll: 1,
  swipeToSlide: true,
  responsive: [{
    breakpoint: 992,
    settings: {
      slidesToShow: 2
    }
  }, {
    breakpoint: 768,
    settings: {
      slidesToShow: 1
    }
  }]
});

Thanks for any suggestions

Khz answered 16/11, 2017 at 8:47 Comment(1)
This answer did the trick for me: #30999576Chlores
K
12

Alright folks, i think i found a quiet easy solution.

We put a wrapper div around the slider with following CSS:

.slider-wrapper {
    width: calc(100% + 30px); //we need more width for the shadows on the edges
    padding: 0 15px; //space for the shadows
    margin-left: -15px; //put the div in its original position
    overflow: hidden; //hide the overflow
}

We make the slick-list div overflow visible:

.slick-list {
  overflow: visible;
}

Thats it for the first part.

Another problem is that the box-shadow of the first element in the overflow is still visible.

This should fix it:

.slick-slide .drop-shadow {
  box-shadow: none; //no shadow for a hidden slide
  transition: box-shadow 0.1s ease-in-out; //little effect to fade the shadow
}

.slick-slide.slick-active .drop-shadow {
  box-shadow: 0px 0px 43px 0px rgba(0, 0, 0, 0.35); //only the active slides have the shadow
}

Here's another demo fiddle: https://jsfiddle.net/cc5fmwaL/2/

I hope i could help someone out and feel free to revise this quick solution.

Khz answered 16/11, 2017 at 9:56 Comment(0)
M
7

An easier solution could be this:

.slick-list {
  box-sizing: initial;
  padding: 25px 0px;
}

Fiddle: https://jsfiddle.net/wouterhendriks/7hu4vj6L/

Measurement answered 17/10, 2018 at 10:17 Comment(0)
P
1

I'm not sure if there are any side effects, but I changed the slick.js source from

.css({
    'width':(100 / _.options.slidesPerRow) + '%',
    'display': 'inline-block'
});

to

.css({
    'width':(98 / _.options.slidesPerRow) + '%',
    'display': 'inline-block'
});

This will leave some space for horizontal box shadow

Pickford answered 5/9, 2018 at 7:58 Comment(1)
Generally you don't want to edit the source, since that's susceptible to getting overwritten, for example during an update.Propagable
D
0

One of the easiest solution i found is:

.slick-list {
  margin: 0 -24px;
  padding: 24px;
}

margin/padding values could be given based upon the blur value you want to add.

Distemper answered 27/7, 2022 at 3:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.