How can I adjust the spacing between slides in Slick?

Is it possible to achieve a layout like this using the slick slider?


  +-------+ +-------+
  |       | |       |
  |    +-------+    |
  +----|       |----+
       |       |
       +-------+

The issue arises when trying to set margins between the slides. I came across a helpful resource on Stack Overflow which explains how you can adjust the margin like so:


/* the slides */
 .slick-slide {
   margin: 0 27px;
 }

/* the parent */
 .slick-list {
   margin: 0 -27px;
 }

However, I'm struggling to make the margin negative in order for the third element to overlap the first two instead of just sitting between them.

Has anyone managed to accomplish this or have any resources that could help with creating a similar effect?

Answer №1

If there are still people interested, I managed to achieve my desired outcome using the following approach:

#container {
    width: 100%;
    display: table;
    table-layout: fixed;
    border-collapse: collapse;
    padding: 10px; /* crucial !! */
}

.slick-slide { /* setting space between each slide */
    margin: 0 -10px;
}

.slick-list { /* setting space between groups of slides */
    padding: 0 20px; 
}

.slick-track { /* adjusting spacing for the slider itself */
    min-height: 600px;
}

.slide {
    position: relative;
    float: left;
}

.slide:nth-child(3n+2) {
    top: 10em;
    z-index: 1;
}

With these CSS styles, I was able to accomplish my initial goal. However, the first slide from each sibling list was still visible. To address this issue, I implemented a script that hides inactive slides and only displays the ones that are currently visible.

$(document).ready(function(){

    /* executed once */ 
    $(".slide").css({opacity: 0}); 
    $(".slick-active").css({opacity: 1});

    /* executed after slide changes */
    $('#container').on('afterChange', function(event, slick, currentSlide, nextSlide){
        $(".slide").animate({opacity: 0}, 100); 
        $(".slick-active").animate({opacity: 1}, 300);
    });
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to Import an Image from a Subdirectory:

Currently, I am working on C# and HTML. While working on a view page, I encountered an issue when trying to load images from subfolders. When attempting to load an image from the immediate folder, it opens correctly. For example: <img data-u="image" s ...

I am having difficulty in crafting a sign-up form accurately

In my HTML file, I have a box that includes a sign-up form: <!-- sign up form --> <div id="cd-signup"> <form class="cd-form" action = "signup.php" > <?php echo "$error" ?> <p clas ...

Smooth transitions: How AJAX calls to PHP chats revolutionize page navigation

When I click the "send button," the page automatically scrolls to the top, which is not the expected behavior. Any suggestions on how to fix this? I've already tried using animations and return false, but nothing seems to be working. Check out the JSF ...

"Revolutionize your time input with Angular's X-editable timepicker or a

Currently, I am utilizing angular x-editable (Editable row) within my Laravel project. My goal is to incorporate a timepicker with some additional configuration, as the x-editable component does not natively support time functionalities. Additionally, I ne ...

Utilizing AJAX to invoke a function

I'm having trouble explaining this, but I'll try my best. I created a function that calculates the remaining amount needed to qualify for free delivery based on different basket value thresholds. Whenever a product is added to the basket, the b ...

Changing the color of a Datatable row through a SQL query in an ASP.NET C# application

I am looking to add color to specific rows in my asp.net c# table. I have a table displayed using an ASP:Repeater with HTML: <div class="panel-body"> <div class="table-responsive"> <table class="table table-striped table-bordered tabl ...

Whenever I open my collapsible dropdown, it seems to leap up unexpectedly

When I interact with the collapsible card, it has a jerky animation. I would like it to open smoothly instead. The issue lies with the tooltip-cus class. If I remove position: relative;, the opening animation is smooth, but then the position of the toolti ...

Tips for retrieving a value with jquery

I am looking to display the name along with the address for each entry. var data = ['{first: era, gold, jack}', '{two: london, USA, India}']; $.each(data, function(index, item) { alert(item); //result era london, gold USA, jack ...

What is the best way to get rid of a connect-flash notification?

I'm having trouble removing the message (with the username displayed) after logging out by pressing the logout button. Every time I try to press the logout button, it just refreshes the page without any action. I want to stay on the same page and not ...

Enhance your form input-group in Bootstrap-4 by adding a stylish border and background-color through validation

I'm working on a form using Bootstrap 4 and I need to display validation errors. Specifically, I want the text field with an input-group for the password to have the same styling as the Username field when there is an error (i.e., red border and backg ...

CSS :hover triggers when hovering AROUND the div element instead of directly OVER it

I'm encountering a subtle yet bothersome issue: I'm attempting to incorporate a "Close" button using CSS image replacement. The HTML code is as follows: <div id='close' title='Close'> <a href='#'> ...

What's causing the issue with the rot-corona animation not functioning properly?

I am currently working on a project related to the coronavirus, and I am having trouble with the animation "rot-corona." I need it to rotate 360 degrees every 3 seconds. Please note that Bootstrap 4 is being used in this project. Code /* SCSS */ #rota ...

Use include files to wrap content in a div tag

I have a webpage index.html with the following JavaScript scripts: <script type="text/javascript> $(document).ready(function() { $('a.link').click(function() {var url = $(this).attr('href'); $('#content'). ...

Using JQuery to create a checkbox with dual functionality within a function

I'm struggling to create a versatile checkbox that will toggle the display of a div from none to block when checked, and back to none when unchecked. I attempted to implement a conditional statement: $("#customCheck1").on("change", function() { if ...

I am having trouble understanding why dropdown menus with the same content have varying widths

My issue is illustrated in the screenshots below: first-dropdown: second-dropdown: The second dropdown appears slightly wider on the right side. Despite Google Chrome's claim that the widths are the same. HTML code: <div class="row menu"> ...

Breaking Down Arrays

The variable b is coming up as undefined and it's being assigned 'a' as the default value when there is no value present. However, when assigned the value of 'c', an error is thrown. Can anyone provide a clear explanation of what i ...

Incorporating Scatter Dots into a Horizontal Stacked Bar Chart using Chart.js

My horizontal stacked bar chart is not displaying pink scatter dots based on the right y axis numbers. I need help figuring out what I am doing wrong. When I change the chart to a normal bar instead of horizontal, the dots appear. However, I require them ...

javascript path as the first argument and callback as the last argument

Currently, I am in the process of creating a wrapper function for expressjs's app.get method. In these methods such as get, you can provide the path, some options, and then the callback. However, it is possible to omit the options and still have it w ...

It appears that when using Python's Selenium to open Chrome, the HTML page is dynamically inserting an iframe element

Recently, I started delving into the world of selenium and web automation, attempting to develop a program to streamline paper searches on PubMed using chromedriver. My primary goal is to automate the process of clicking the "Sign in" button located in th ...

Embracing unconventional attributes within AngularJS

After converting my model from Java to JavaScript using GWT 2.7, I have a set of properties with getValue() and setValue() methods that are not obfuscated. I am interested in using these properties in {{}} expressions, especially for data binding with ngM ...