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).
$('.single-item').slick({
initialSlide: 3,
infinite: false
});
.slick-slider {
margin:0 -15px;
}
.slick-slide {
padding:10px;
background-color:red;
text-align:center;
margin-right:15px;
margin-left:15px;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://cdn.jsdelivr.net/jquery.slick/1.5.0/slick.min.js"></script>
<link href="http://cdn.jsdelivr.net/jquery.slick/1.5.0/slick.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-12" style="background-color:gray;">
<div class="slider single-item" style="background:yellow">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</div>
</div>
</div>
Somehow I am getting space from both side, I am trying to remove that.
Just fix css:
The slick-slide has inner wrapping div which you can use to create spacing between slides without breaking the design:
Since the latest versions you can simply add
margin
to your slided:There's no need for any kind of negative margin's, since slick's calculation is based on the elements
outterHeight
.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
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
Another option is to define a slide's width by css without setting to amount of slides to show.