In the code below there are two .wrapper
divs
, creating two carousels with slick.js. In the upper carousel there are two images, in the second carousel four images. In the initialisation of slick slidesToShow
is set to 4.
The two images on the first carousel are centered horizontally, but I need them to be left aligned. How to left-align the carousel images? Images should be the same size for both carousels.
Code html head:
<link rel="stylesheet" type="text/css" href="slick/slick.css"/>
<link rel="stylesheet" type="text/css" href="slick/slick-theme.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
CSS:
.wrapper div {
padding: 10px;
}
.wrapper img {
width: 100%;
height: auto;
}
JS:
$(document).ready(function(){
$('.wrapper').slick({
infinite: true,
slidesToShow: 4,
slidesToScroll: 4,
responsive: [
{
breakpoint: 1000,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
},
{
breakpoint: 650,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
},
]
});
});
HTML body:
<div class="wrapper">
<div>
<img src="http://via.placeholder.com/200x200" width="200" height="200" alt="" />
<p>title</p>
</div>
<div>
<img src="http://via.placeholder.com/200x200" width="200" height="200" alt="" />
<p>title</p>
</div>
</div>
<div class="wrapper">
<div>
<img src="http://via.placeholder.com/200x200" width="200" height="200" alt="" />
<p>title</p>
</div>
<div>
<img src="http://via.placeholder.com/200x200" width="200" height="200" alt="" />
<p>title</p>
</div>
<div>
<img src="http://via.placeholder.com/200x200" width="200" height="200" alt="" />
<p>title</p>
</div>
<div>
<img src="http://via.placeholder.com/200x200" width="200" height="200" alt="" />
<p>title</p>
</div>
</div>
<script type="text/javascript" src="slick/slick.min.js"></script>
I tried the following, which works, but I prefer not to change slick.js generated code for maintenance reasons:
.slick-track {
margin-left: 0;
margin-right: 0;
}
Is there a more appropriate way to left align the images?