React-slick: how can i set slide item margin ?

Created on 29 Aug 2016  路  10Comments  路  Source: akiran/react-slick

I saw the code write this in mixins.helpers.initialize and line 30
var slideWidth = trackWidth / props.slidesToShow;

But i want add margin or padding on slidesItem rather than each mixed together
like this:
var slideWidth = (trackWidth+padding*2) / props.slidesToShow;

I saw the examples,every slides item not mixed together.

and however i can use css like padding:0 10px; to resolve it

Is there any options to set it?

Most helpful comment

I fixed it using

.slick-slide {
  padding: 0 15px;
}

.slick-list {
  margin: 0 2em;
}

All 10 comments

Using css is the best way to control margin/padding on slides

@V-Tom Did you ever happen to find a good solution to this? Like @akiran says you can set margin or padding on the slides, but the next slide and previous slide button don't respect that and end up not left-aligning the slides with the start of the carousel.

My workaround around this issue was to wrap my slides with an additional <div/> which has a padding-right set for the amount of desired margin:

Relevant configuration

{      
  centerMode: true,
  slidesToShow: 1,
  slidesToScroll: 1,
  centerPadding: 30
}

JSX

<div className="item">
  <SlideElement>...</SlideElement>
</div>

CSS

.item {
  padding-right: 10px;
}

A solution that worked well for our team was to add a thick border to each item that is the same color as the background. This way the padding doesn't affect the carousel in any way.

@mcmillhj-wta That worked really well for me as well, in combination with setting the box-sizing property to "border-box".

What did work for me, is this:
I wrapped my item with a container that have height bigger than the item itself, and then I deleted the margin from my item ;)

I fixed it using

.slick-slide {
  padding: 0 15px;
}

.slick-list {
  margin: 0 2em;
}

I ended up adding margin to the element inside ..slick-slide and then add negative margin on .slick-list

e.g.

.slick-slide img {margin-left:10px;}
.slick-list {margin-left:-10px;}

You dont need to set margins just set:

 .slick-slide {
         padding: 0 8px;
         box-sizing: border-box;
  }

padding-left/right depends on your centerPadding.

I fixed it using

.slick-slide {
  padding: 0 15px;
}

.slick-list {
  margin: 0 2em;
}

many thanks, it worked in my case!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BradyEdgar94 picture BradyEdgar94  路  3Comments

walker-jiang picture walker-jiang  路  3Comments

slashwhatever picture slashwhatever  路  3Comments

will88 picture will88  路  3Comments

PolGuixe picture PolGuixe  路  3Comments