How add spaces between Slick carousel item

后端 未结 13 2584
野性不改
野性不改 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:58

    The slick-slide has inner wrapping div which you can use to create spacing between slides without breaking the design:

    .slick-list {margin: 0 -5px;}
    .slick-slide>div {padding: 0 5px;}
    
    0 讨论(0)
  • 2020-12-04 19:59

    An improvement based on the post by Dishan TD (which removes the vertical margin as well):

      .slick-slide{
        margin-left:  15px;
        margin-right:  15px;
      }
    
      .slick-list {
        margin-left: -15px;
        margin-right: -15px;
        pointer-events: none;
      }
    

    Note: the pointer-events was necessary in my case, to be able to click on the left arrow.

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

    For example: Add this data-attr to your primary slick div: data-space="7"

                        $('[data-space]').each(function () {
                            var $this = $(this),
                                $space = $this.attr('data-space');
    
                            $('.slick-slide').css({
                                marginLeft: $space + 'px',
                                marginRight: $space + 'px'
                            });
    
                            $('.slick-list').css({
                                marginLeft: -$space + 'px',
                                marginRight: -$space/2 + 'px'
                            })
                        });
    
    0 讨论(0)
  • 2020-12-04 20:02

    Yup, I have found the solution for dis issue.

    • Create one slider box with extra width from both side( Which we can use to add item space from both sides ).
    • Create Inner Item Content with proper width & margin from both sides( This should be your actual wrapper size )
    • Done
    0 讨论(0)
  • 2020-12-04 20:03
        /* the slides */
      .slick-slide {
        margin: 0 27px;
      }
      /* the parent */
      .slick-list {
        margin: 0 -27px;
      }
    

    This problem reported as issue (#582) on plugin's github, btw this solution mentioned there too, (https://github.com/kenwheeler/slick/issues/582)

    0 讨论(0)
  • 2020-12-04 20:04

    Just fix css:

    /* the slides */
    .slick-slider {
        overflow: hidden;
    }
    /* the parent */
    .slick-list {
        margin: 0 -9px;
    }
    /* item */  
    .item{
        padding: 0 9px;
    }
    
    0 讨论(0)
提交回复
热议问题