Resize a responsive grid of images

Within my slider, I have three slides with 3 images each. The layout consists of one large image on the left and two smaller ones on the right. To ensure responsiveness, I've used max-width: 100% on the images so they can scale down proportionally as the window size changes.

I purposely did not set fixed heights/widths for the images to allow them to adjust dynamically. However, when the window width shrinks past the container's width, the small images on the right shift to the next line.

How can I maintain the side-by-side arrangement of the images while resizing the browser window and make sure they resize responsively without causing scrollbars to appear?

$('.slider').slick();
body {
  background: purple;
}
.slider {
  max-width: 800px;
  margin: 0 auto;
}
.slide {
  width: 100%;
}
.bigImg,
.smallImg {
  float: left;
}
img {
  max-width: 100%;
  height: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/jquery.slick/1.3.6/slick.min.js"></script>
<link href="http://cdn.jsdelivr.net/jquery.slick/1.3.6/slick.css" rel="stylesheet" />

<div class="slider">
  <div class="slide">
    <div class="bigImg">
      <img src="http://dummyimage.com/600x400/000/fff" />
    </div>
    <div class="smallImg">
      <img src="http://dummyimage.com/200x200/000/fff" />
    </div>
    <div class="smallImg bl">
      <img src="http://dummyimage.com/200x200/000/fff" />
    </div>
  </div>
  <div class="slide">
    <div class="bigImg">
      <img src="http://dummyimage.com/600x400/000/c00" />
    </div>
    <div class="smallImg">
      <img src="http://dummyimage.com/200x200/000/c00" />
    </div>
    <div class="smallImg bl">
      <img src="http://dummyimage.com/200x200/000/c00" />
    </div>
  </div>
  <div class="slide">
    <div class="bigImg">
      <img src="http://dummyimage.com/600x400/333/aaa" />
    </div>
    <div class="smallImg">
      <img src="http://dummyimage.com/200x200/333/aaa" />
    </div>
    <div class="smallImg bl">
      <img src="http://dummyimage.com/200x200/333/aaa" />
    </div>
  </div>
</div>

Answer №1

Give this a try

$('.slider').slick();
body {
  background: purple;
}
.slider {
  max-width: 800px;
  margin: 0 auto;
}
.slide {
  width: 100%;
  overflow: hidden; /*Updated code*/
}
   
.bigImg,
.smallImg {
  float: left;
  width: 25%;  /*Newly modified code*/
}
 .bigImg {
  width: 75%; /*Newly modified code*/
}
img {
  max-width: 100%;
  height: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/jquery.slick/1.3.6/slick.min.js"></script>
<link href="http://cdn.jsdelivr.net/jquery.slick/1.3.6/slick.css" rel="stylesheet" />

<div class="slider">
  <div class="slide">
    <div class="bigImg">
      <img src="http://dummyimage.com/600x400/000/fff" />
    </div>
    <div class="smallImg">
      <img src="http://dummyimage.com/200x200/000/fff" />
    </div>
    <div class="smallImg bl">
      <img src="http://dummyimage.com/200x200/000/fff" />
    </div>
  </div>
  <div class="slide">
    <div class="bigImg">
      <img src="http://dummyimage.com/600x400/000/c00" />
    </div>
    <div class="smallImg">
      <img src="http://dummyimage.com/200x200/000/c00" />
    </div>
    <div class="smallImg bl">
      <img src="http://dummyimage.com/200x200/000/c00" />
    </div>
  </div>
  <div class="slide">
    <div class="bigImg">
      <img src="http://dummyimage.com/600x400/333/aaa" />
    </div>
    <div class="smallImg">
      <img src="http://dummyimage.com/200x200/333/aaa" />
    </div>
    <div class="smallImg bl">
      <img src="http://dummyimage.com/200x200/333/aaa" />
    </div>
  </div>
</div>

Answer №2

To ensure the correct proportions are maintained, adjust the width of the image containers using a percentage:

.largeImage{
  width: 70%;
}
.smallImage{
  width: 30%;
}

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

The dynamic JavaScript in Bootstrap 4 seems to be malfunctioning, despite working perfectly in Bootstrap 3

I am currently implementing a dynamic modal feature using the code snippet below: // Show Ajax modal with content $(document).on('click', '[data-modal]', function (event) { event.preventDefault(); $.get($(this).data('moda ...

Utilize CSS to exclusively filter through items

Is it possible to use CSS alone to filter a list of items based on specific links being clicked? I have a list that should display only certain items when corresponding links are clicked. HTML: <!-- Header links --> <a href="#" class="all" tabin ...

Executing a jQuery.ajax call using a proxy server

I'm currently working on a Chrome extension and I have encountered an issue. When making a jQuery.ajax request for a standard HTTP page from a page served via HTTPS, Chrome blocks the request. This has led me to consider if it would be feasible to ret ...

Mastering the art of looping through an array efficiently in jQuery using AJAX without unnecessary repetition

I have a jQuery function that extracts values from the wp_localize_script declaration. <script type='text/javascript'> /* <![CDATA[ */ var assjs = {"action":"get_ass_counts","path":"http:\/\/localhost\/wordpress-dev\ ...

Using Wordpress's built-in feature for displaying images in the admin panel can enhance the user experience and make

I'm currently in the process of developing a unique Wordpress plugin for one of my customers and I really want to incorporate a modal popup feature on the admin page. After experimenting with ThickBox, LightBox, and Fancybox, none of them seem to do t ...

Internet Explorer is failing to show the results of an ajax call retrieved from the

Need help with this code block: $(document).ready(function() { dataToLoad = 'showresults=true'; $.ajax({ type: 'post', url: 'submit.php', da ...

What is the best way to display a default image in a kendo grid when the image field is empty?

I am trying to display a default image if the image field is empty. Below is the code for the image field: { field: "Photo", title: "Photo", template: '<img src="#= Photo ? Photo : 'default.jpg' #" alt="image" width="80px" height="80px" ...

Unable to locate the CSS for the selected dropdown button in Bootstrap

Seeking help to locate the CSS code responsible for the blue border on a select dropdown button in Bootstrap. It seems simple, but I'm unable to find it. If anyone knows where this specific class is located in the CSS file, please share your insights ...

What steps should I take to refresh my Partial View after a successful form submission?

Greetings, I hope this message finds you well. I have a help page on my website that includes an FAQ section (content served from a Web Service) and a button that displays a partial view. The partial view collects help request information and submits it to ...

a personalized attribute value obtained from executing a function

I am looking to increase a number in the attribute of a div by clicking on a button. The attribute in question is "data-count" and the button is labeled as "insert". The value generated by the function needs to be added to the existing attribute's val ...

Tips for positioning elements on an HTML page by utilizing CSS styling

I have a primary container with the following CSS: .major { width:30%; height:100%; position:absolute; } Now, I want to insert web information at the bottom part which includes: About | Terms | Policies | Contact Us This content will be within the .web ...

Do not engage with the website while animations are running

I'm working on a JavaScript project where I want to create textareas that grow and center in the window when clicked, and shrink back down when not focused. However, I ran into some issues with the .animate() function that are causing bugs. During QA ...

Unexpected error occurred when attempting to fetch the jQuery value of the radio button: "Unrecognized expression syntax error"

I am facing an issue while trying to extract the value of a radio button using $("input[@name=login]"); I keep getting an "Uncaught Syntax error, unrecognized expression" message. To view the problem, visit http://jsfiddle.net/fwnUm/. Below is the complet ...

What is the process for including the Authorization HTTP header in a JSONP request?

I am attempting to make a GET request to the Yelp API. When I use the code below, I encounter a 401 error. From my research, it seems that setting the authorization in this manner is not possible when requesting JSONP data. However, when I attempt another ...

Is there a way to eliminate a div and all its contents from the DOM?

As I work on my web application, I am trying to implement a system where error messages can be returned via ajax upon success or failure. The ajax script is functioning correctly in terms of returning errors or successes. However, my challenge lies in com ...

Troubleshooting Challenges with JavaScript DOM Manipulation

I am facing an issue with a table where I need the first column to remain fixed when scrolling horizontally. The code snippet below works perfectly for the first column of td's, but fails to work for the tr's. Despite checking the code thoroughly ...

Preventing HTML form from being resubmitted upon page refresh after submission

I am facing an issue with my HTML form. Whenever I click submit, the form data is sent to the same php page. However, after submitting, when I refresh the page, the web browser shows a re-submission dialog. How can I prevent the form from submitting again ...

Setting up a custom PrimeNG theme to match our unique style is a great way to

I am currently using the most recent version of "primeng": "^12.2.0", and I am looking to implement my own custom theme for primeng. Despite searching through numerous blogs, I have yet to find a solution. In an attempt to create my cu ...

Utilizing HTML data retrieved from an ajax request

I am utilizing a load more button to display content fetched from a database via ajax. Here is how the ajax call is structured: // JavaScript Document // Function to load more builds $(document).ready(function(){ var pageIndex = 1; $('#loadmorebuild ...

Do not request for this element within the array

I have a function that applies to all elements in an array, except for the currently clicked one. For example: cubesmixed = [array, with, 145, elements] cubesmixed[54].click(function() { for(var i = 0; i < 145; i++) { var randomnumber=Math.flo ...