How to match Slick Slider slide width with Bootstrap container width

Utilizing the slick slider from http://kenwheeler.github.io/slick/ to showcase 3 slides side by side with the center slide displayed in the middle.

This website is built on Bootstrap 4 framework and I want the slides to have the same width as the Bootstrap container. This way, the active (centered) slide will perfectly align with the other elements within the container. The left and right slides should expand to the edges of the screen.

In essence, the slider should occupy the full width so that the left and right slides can stretch to the end of the screen while only the active slide is aligned with the container DIV.

Refer to this example for a visual representation: https://codepen.io/cray_code/pen/BXzxgP

Here's my current code:

$('.slider').slick({
  infinite: true,
  slidesToShow: 1,
  slidesToScroll: 1,
  centerMode: true,
  enterPadding: '60px',
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container bg-light py-5 my-5">

  <h1>Container</h1>
  <h4>The slides should be the same width as the container
    <h4>

</div>


<div class="slider bg-light py-5 my-5">
  <div class="bg-dark text-white py-5">
    <h2>Slide 1</h2>
  </div>
  <div class="bg-dark text-white py-5">
    <h2>Slide 2</h2>
  </div>
  <div class="bg-dark text-white py-5">
    <h2>Slide 3</h2>
  </div>
  <div class="bg-dark text-white py-5">
    <h2>Slide 4</h2>
  </div>
  <div class="bg-dark text-white py-5">
    <h2>Slide 5</h2>
  </div>
</div>


<div class="container bg-light py-5 my-5">

  <h1>Container</h1>

</div>

I attempted to assign fixed widths to the slides across various viewports, but faced issues due to variable slide widths.

Is there an alternative solution to achieve this?

Answer №1

I may not fully grasp your question, but I made some changes to your code.

To ensure alignment with other sections, I added a container class to the slider div and modified slidesToShow: 3,

$('.slider').slick({
infinite: true,
slidesToShow: 3,
slidesToScroll: 1,
centerMode: true,
enterPadding: '60px',
});
.slick-slide {opacity: 0.2; margin: 0 2rem;}
.slick-slide.slick-active {opacity: 1;}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6a5babfb5bdfbb5b7a4b9a3a5b3ba96e7f8eef8e7">[email protected]</a>/slick/slick.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0b3aca9a3abeda3a1b2afb5b3a5ac80f1eef8eef1">[email protected]</a>/slick/slick.css">

 
<div class="container bg-light py-5 my-5">

<h1>Container</h1>
<h4>The slides should be the same width as the container<h4>

</div>


<div class="container slider bg-light py-5 my-5">
<div class="bg-dark text-white py-5">
<h2>Slide 1</h2>
</div>
<div class="bg-dark text-white py-5">
<h2>Slide 2</h2>
</div>
<div class="bg-dark text-white py-5">
<h2>Slide 3</h2>
</div>
<div class="bg-dark text-white py-5">
<h2>Slide 4</h2>
</div>
<div class="bg-dark text-white py-5">
<h2>Slide 5</h2>
</div>
</div>


<div class="container bg-light py-5 my-5">

<h1>Container</h1>

</div>

Answer №2

Have you tried creating a div with the class "row" and placing a "col-md-6 col-12" inside it? You can then add the desired content within the slick div, and repeat this for other sections to see if it yields the expected outcome.

Answer №3

Initially: Eliminate any margins from the .slick-slide class

.slick-slide {opacity: 0.2;}

Next, turn off centerMode and set enterPadding to zero. Here's how:

$('.slider').slick({
    infinite: true,
    slidesToShow: 1,
    slidesToScroll: 1,
    centerMode: false,
    enterPadding: 0,
});

Surround your slider block with a container class

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

calculating the rotation angle from the origin to a vector within a three-dimensional space using three.js

I am working with a vector in three-dimensional space. Is there a method to determine the angle of rotation from the origin to this vector on each axis? For example, if the vector is located at x=6, y=-10, z=20, what angle does the vector make with resp ...

How come my jQuery toggle is not functioning properly?

Can anyone help with my project? I'm having issues with my toggle function and I can't seem to figure out what's wrong. $('.col1-text').click(function() { $(this).find('.col1-info').toggle(function() { $(this ...

With TypeScript, you have the flexibility to specify any data type in the generic types when using the axios.get method

axios.get('/api') When working with TypeScript as shown above, it is important to designate types for better clarity. This allows us to reference the type definition of axios, like so: (method) AxiosInstance.get<any, AxiosResponse<any> ...

Add a fresh item into an array in Json between existing elements

After looping through a JSON object using foreach, the output is as follows: {"Comment": {"id":"1","post_id":"31","created":"14263241"} , "User": {"fname":"Test","lname":"Test2"} } {"Comment": {"id":"2","post_id":"32","created":"14263257"} , "User": {"f ...

Convenient ways to connect data between a database and Firebase authentication system

After beginning a basic app using Firebase 3 and Angular 1, I implemented an authentication system through Firebase for user registration and login. Currently, I am storing message data in the Firebase database. My main question is: how can I connect user ...

What causes the v-for in a template to only update when the input text changes?

I'm currently working on a Vue.js code, but I'm facing an issue where the template isn't updating when new data is added to the input text. My goal is for the list to update when the @click event occurs. Visit this link for reference metho ...

What is the best way to fetch Ajax information for use in several drop-down menus?

Is there a way to populate one multiple select drop-down based on the selection made in another multiple select drop-down using jQuery or ajax? Here is an example of how I am attempting to achieve this using ajax: function demo1() { var emp_id = docu ...

Using jQuery to swap out sections of a HTML tag

Similar Question: Use of jQuery for Modifying an HTML Tag? After extensive research, I have not come across a solution that fits my specific requirements. My objective is to replace a part of an HTML tag without completely replacing the entire tag. To ...

Using components from other modules in a sibling module's component in Angular 4

Let me provide some context - I'm currently working with Angular 4 and the AngularCLI. The structure of my folders looks like this: app helper-components helper-components.module.ts views admin admin.module.ts views.m ...

The error message states that the property "user" is not found in the type "Session & Partial<SessionData>"

I recently had a javascript code that I'm now attempting to convert into typescript route.get('/order', async(req,res) => { var sessionData = req.session; if(typeof sessionData.user === 'undefined') { ...

Issue with Jquery Fatnav - active state not functioning properly

Currently, I am implementing a Jquery plugin known as fatNav. The documentation for the plugin can be found here: https://github.com/Glitchbone/jquery-fatNav Although everything is functioning properly, I am encountering difficulty getting my active stat ...

Utilize Python 3.7 to mark a checkbox on an HTML webpage

I am currently attempting to use Python 3.7 and Selenium to select a checkbox on an HTML page. My ultimate goal is to manipulate these checkboxes, but I am struggling to even select them correctly. The URL in question is: Prior to seeking assistance here, ...

Tips for selecting a title bar in a custom jqgrid

I need to display a message in just one of the multiple grids on my screen. However, the current code I am using attaches the message to all the grids. $(".ui-jqgrid-titlebar").append("<span>Error Message</span>"); Is there a way for me to ta ...

Objective-C and the World of WebSockets

Possible Duplicates: Comparison of WebSockets, TCP/IP, and JavaScript/AJAX for iPhone chat Integrating WebSockets into a Cocoa application Hello all, our team is embarking on creating a bespoke iPhone chat app and deliberating the use of WebSocket ...

Empty form field when submitting form using ajax in C# MVC

I am encountering an issue while attempting to store form data in a database using $.ajax. The problem lies in the fact that upon submitting the form, the username is being saved as null, whereas the email and password are correctly stored. function Sav ...

Load a gallery of images using JavaScript Ajax

I need help loading multiple images from Ajax results into a list of objects. $('#div-images').empty(); for (var key in data.listImage) { var mi = data.listImage[key]; var image_url = mi.IMAGE_URL; var image_tag = '<img id=image&ap ...

The left and right edges are not extending across the entire screen

Can anyone help me determine if this is a duplicate issue? I'm unsure why my left and right borders are not extending the full width of the screen. The website in question is ojs.monojitbanerjee.co.cc Here is the structure: <body> <div id= ...

How can I filter rows in HTML using Vue.js based on string options?

When selecting different options, I want to dynamically add new rows. For instance, if "kfc" is selected, a specific row should be added. If "cemrt" is chosen, another row needs to be included. <div class="card-content" v-for="(bok, index) in rules" :k ...

Implement a slideshow feature that automatically changes a CSS attribute when preview images are shown

(Apologies for the perplexing title) My intention was to create a slideshow gallery, and I stumbled upon an example here: https://www.w3schools.com/howto/howto_js_slideshow_gallery.asp In this setup, you'll notice previews of images in a small bar b ...

Assigning a value to a variable using conditional IF statements and the Alert function in JavaScript

How can I set a variable value based on conditions and display an Alert in JavaScript? Hello, I have a code that utilizes Alerts to display the results of evaluating the visibility status of two controls using jQuery. If pnlResultados is visible, it will ...