The scaling of the slick carousel image is not working as expected

Having an issue with the Slick carousel where images are not resizing based on browser size (original size is 300x228px).

Just to clarify: When I shrink the browser window, the number of slides decreases but the images remain the same size.

I've been attempting to resolve this problem without any luck so far. Here is the current code I am using.

     $(document).on('ready', function () {
            $(".slideslick").slick({
  autoplay: true,
  autoplaySpeed: 5000,
  slidesToShow: 2,
  arrows: false,
  responsive: [
    {
      breakpoint: 880,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }
    // You can unslick at a given breakpoint now by adding:
    // settings: "unslick"
    // instead of a settings object
  ]
});

        });
.slideslick {
          width: 100%;
          margin: 0px auto;
        }
        .slide1 img {
          position: relative;
          margin-right: auto;
          margin-left: auto
        }
        .slide2 img {
          position: relative;
          margin-right: auto;
          margin-left: auto
        }
        .slide3 img {
          position: relative;
          margin-right: auto;
          margin-left: auto
        }
        .slide4 img {
          position: relative;
          margin-right: auto;
          margin-left: auto
        }
        .slide5 img {
          position: relative;
          margin-right: auto;
          margin-left: auto;
        }
        .slick-slide{
          width: 300px
        }
        .slick-slide img{
          max-width: 100%;
          height: auto;
          min-width: 200px;
          min-height: 150px;
        }
<div class="slideslick">   
        <div class="slidercontent1">
            <div class="slide1">
                <img draggable="false" src="assets/images/incomparablesdelamor.png">
            </div>
        </div>
        <div class="slidercontent2">
            <div class="slide2">
                <img draggable="false" src="assets/images/sorayamantari.png">
            </div>
        </div>
        <div class="slidercontent3">
            <div class="slide3">
                <img draggable="false" src="assets/images/nandodelmantaro.png">
            </div>
        </div>
        <div class="slidercontent4">
            <div class="slide4">
                <img draggable="false" src="assets/images/nandodelmantaro.png">
            </div>
        </div>
        <div class="slidercontent5">
            <div class="slide5">
                <img draggable="false" src="assets/images/nandodelmantaro.png">
            </div>
        </div>
</div>

Answer №1

Implement a media query that adjusts the width of the image to 100% when the screen width is less than 800px

@media(max-width:800px) {
  .slick-slide img {
    width: 100%;
  }
}

$(document).on('ready', function() {
  $(".slideslick").slick({
    autoplay: true,
    autoplaySpeed: 5000,
    slidesToShow: 2,
    arrows: false,
    responsive: [{
        breakpoint: 880,
        settings: {
          slidesToShow: 1,
          slidesToScroll: 1
        }
      }
      // You can unslick at a given breakpoint now by adding:
      // settings: "unslick"
      // instead of a settings object
    ]
  });

});
.slideslick {
  width: 100%;
  margin: 0px auto;
}

.slide1 img {
  position: relative;
  margin-right: auto;
  margin-left: auto
}

.slide2 img {
  position: relative;
  margin-right: auto;
  margin-left: auto
}

.slide3 img {
  position: relative;
  margin-right: auto;
  margin-left: auto
}

.slide4 img {
  position: relative;
  margin-right: auto;
  margin-left: auto
}

.slide5 img {
  position: relative;
  margin-right: auto;
  margin-left: auto;
}

.slick-slide {
  width: 300px
}

.slick-slide img {
  max-width: 100%;
  height: auto;
  min-width: 200px;
  min-height: 150px;
}

@media(max-width:800px) {
  .slick-slide img {
    width: 100%;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5b6a9aca6aee8a6a4b7aab0b6a0a985f4ebfdebf4">[email protected]</a>/slick/slick.css" />
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0477686d676f296765766b7177616844352a3c2a35">[email protected]</a>/slick/slick.min.js"></script>
<div class="slideslick">
  <div class="slidercontent1">
    <div class="slide1">
      <img draggable="false" src="https://placehold.it/500x200">
    </div>
  </div>
  <div class="slidercontent2">
    <div class="slide2">
      <img draggable="false" src="https://placehold.it/500x200">
    </div>
  </div>
  <div class="slidercontent3">
    <div class="slide3">
      <img draggable="false" src="https://placehold.it/500x200">
    </div>
  </div>
  <div class="slidercontent4">
    <div class="slide4">
      <img draggable="false" src="https://placehold.it/500x200">
    </div>
  </div>
  <div class="slidercontent5">
    <div class="slide5">
      <img draggable="false" src="https://placehold.it/500x200">
    </div>
  </div>
</div>

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

I'm trying to create a horizontal list using ng-repeat but something isn't quite right. Can anyone help me figure out

Feeling a bit lost after staring at this code for what seems like an eternity. I'm trying to create a horizontal list of 2 image thumbnails within a modal using Angular's ng-repeat. Here's the HTML snippet: <div class="modal-body"> ...

Refreshing a page following an AJAX request made with jQuery

I am working on a JSP page that shows student details. When a student is selected from the dropdown box, it triggers an onchange event to retrieve the minimum and maximum marks for that student. <form name="listBean"> <c:forEach var="Item" i ...

What about CSS block elements that have a width relative to their parent container

My goal is to create a layout where each h3 and p element is wrapped in a box. The current issue I'm facing is that the blocks extend to full width due to h3 and p being block level elements. The desired outcome is for the width of the boxes to adjus ...

PHP 7.2 does not allow code to reference previously set sessions

Currently, I am utilizing sessions to transmit either a success or error message to the subsequent site by employing an included PHP file (message.php) to exhibit said message. Unfortunately, for unknown reasons, the message.php file is unable to referenc ...

Python script for extracting content from web pages that are loaded dynamically

I am facing an issue with extracting content from a webpage on my website. Despite trying to use selenium and clicking buttons, I have not been successful. #!/usr/bin/env python from contextlib import closing from selenium.webdriver import Firefox import ...

Unable to connect to React Node Socket.IO application from any source other than localhost using IPv4 and NGROK

I recently followed a tutorial on creating a simple React app/Node with Socket.IO. The tutorial worked perfectly, so I decided to test it with two other devices: One PC on the same wifi network (via IPv4 - 192.168.1.8:3000) A mobile device using Ngrok tun ...

Wind - Best practices for managing the status of multiple entities within a single display prior to executing the save changes function

In my system, there are three main entities: Project, Attachment, and Messages. A project can have multiple attachments and messages associated with it. The issue arises on the project detail view, where I display the project's messages and any attac ...

Using Ember's transitionTo method and setting a controller attribute within a callback

I am working with Ember code to transition to a specific route while also setting controllerAttr1 on 'my.route' Upon transitioning to "my.route" using this.get('router').transitionTo("my.route"), I have set up a callback function that ...

What is the method to trigger a function upon opening an anchor tag?

When a user opens a link in my React app, I need to send a post request with a payload to my server. My current strategy involves using the onClick and onAuxClick callbacks to handle the link click event. However, I have to filter out right-clicks because ...

I seem to be having trouble with the Clearfix - the elements at the bottom are overflowing the container

Hey there! I'm having some trouble with my website, specifically at the bottom where the letters and hr line are overflowing the container. I thought about using a clearfix, but it doesn't seem to be working as expected. I even tried adding an ov ...

Is there a way to ensure that the fixed modal remains at the forefront and that its top stays in view even as the user scrolls?

Can you assist me in simplifying this code? import { LoginProps } from '@/layouts/layout.props'; import { Box, Button, Divider, Flex, FormControl, FormLabel, Heading, HStack, IconButton, Input, Link, Stack, Text, } from ...

The postMessage function in my Javascript SlackBot seems to be flooding the channel with messages

I am currently setting up a Slack bot using JavaScript combined with several useful libraries. The main function of this bot is to execute a postMessageToChannel method whenever a user in the channel mentions the specific keyword "help." However, I am fa ...

Schedule - the information list is not visible on the calendar

I am trying to create a timeline that loads all data and events from a datasource. I have been using a dev extreme component for this purpose, but unfortunately, the events are not displaying on the calendar. Can anyone offer any insights into what I might ...

Utilizing jQuery to emphasize a selected table row upon radio button selection

When I have a table (standard markup) with a radio select in each row, I want to highlight the selected radio button. It seems simple, but for some reason it's not triggering as expected. Here is the example of the markup: The Table Row: <tr> ...

Styling a rectangle in p5.js: Tips and tricks

In my p5.js code, I created a rectangle using rect(): rect(10, 10, 10, 10); Now, I want to add some style to it with a box-shadow effect: box-shadow: 20px 20px 50px #00d2c6, -30px -30px 60px #00ffff; However, when I tried to apply the style using the doc ...

Styles and CSS have been successfully loaded, however, the content is not appearing

After attempting to import a web HTML CSS template into my self-made MVC, I encountered an issue. While the template works properly on its own, it fails to connect to the CSS files and display proper styles when accessed through my controller. Instead, onl ...

Issue with React hook state persistence in recursive function

I implemented a recursion custom hook that utilizes a setTimeout function to provide 3 chances for an operation. Once the chances run out, the recursion should stop. However, I encountered an issue where the setTimeout function is not properly decrementin ...

Show Pop in relation to modified Text

When the user clicks on the text, a pop-up is displayed after the last word in the text.... https://i.stack.imgur.com/VWQCa.png The logic being used is : left = layer.width + layer.x Code : document.getElementById(lightId).style.left = layer.x + docume ...

What is the best way to update information in the `App` component using Vue?

Within Vue, I have an App component that utilizes the <router-view> to extend the functionality of a Login component. My goal is to update specific data within the App component when a button is clicked in the Login component. Is this type of inter ...

How do I create a Bootstrap 4 multi-level navigation bar that drops to the right on the third level?

clickable dropdown hover dropdown.jpg Source: Is there a way to create a dropdown menu that opens to the right like the clickable version, rather than to the left like the hover dropdown in the provided example? I'm open to other solutions as long ...