How add spaces between Slick carousel item

后端 未结 13 2583
野性不改
野性不改 2020-12-04 19:41

I want to add space between two slick carousel items, but not want the space with padding, because it\'s reducing my element size(and I don\'t want that).

相关标签:
13条回答
  • 2020-12-04 19:44

    Try to use pseudo classes like :first-child & :last-child to remove extra padding from first & last child.

    Inspect the generated code of slick slider & try to remove padding on that.

    Hope, it'll help!!!

    0 讨论(0)
  • 2020-12-04 19:45

    Since the latest versions you can simply add a margin to your slides:

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

    There's no need for any kind of negative margins, since slick's calculation is based on the elements outerHeight.

    0 讨论(0)
  • 2020-12-04 19:45

    simply add padding on to the slick-side class will do

    .slick-slider .slick-slide {
      padding: 0 15px;
    }
    
    0 讨论(0)
  • 2020-12-04 19:49

    @Dishan TD's answer works nice, but I'm getting better results using only margin-left.

    And to make this clearer to everyone else, you have to pay attention to the both opposite numbers: 27 and -27

      /* the slides */
      .slick-slide {
        margin-left:27px;
      }
    
      /* the parent */
      .slick-list {
        margin-left:-27px;
      }
    
    0 讨论(0)
  • 2020-12-04 19:51

    If you want a bigger space between the slides + not to decrease the slide's width, it means you'll have to show less slides. In such case just add a setting to show less slides

        $('.single-item').slick({
          initialSlide: 3,
          infinite: false,
          slidesToShow: 3
        });
    

    Another option is to define a slide's width by css without setting to amount of slides to show.

    0 讨论(0)
  • 2020-12-04 19:55

    With the help of pseudo classes removed margins from first and last child, and used adaptive height true in the script. Try this fiddle

    One more Demo

     $('.single-item').slick({
            initialSlide: 3,
            infinite: false,
            adaptiveHeight: true
        });
    
    0 讨论(0)
提交回复
热议问题