Maintain uniform height of divs while adjusting image size without altering padding

My challenge lies in creating a layout of images in columns with consistent padding between them. The ultimate goal is to ensure that the images align at the bottom, regardless of screen size variations as depicted in this image:

The problem arises when the images (set to width:100%;) scale on different screens, causing the padding of 15px to remain constant and not adjust accordingly. This requires a change in column widths to maintain consistent heights.

After exhausting CSS options, I turned to jQuery for a solution:

HTML

<div class="row">
  <div class="eHeightStacked">
    <img src="image.jpg" />
    <img src="image.jpg" />
    <img src="image.jpg" />
  </div>
  <div class="eHeightSingle">
    <img src="image.jpg" />
  </div>
</div>

jQuery

var eRatio1 = $('.eHeightStacked').height() / $('.eHeightStacked').width(),
    eRatio2 = $('.eHeightSingle').height() / $('.eHeightSingle').width(),
    rowWidth = $('.row').width();       

var eWidth1 = eRowWidth*eRatio2 / (eRatio1+eRatio2), 
    eWidth2 = eRowWidth-eWidth1;

$('.eHeightStacked').width( Math.round(eWidth1) );
$('.eHeightSingle').width( Math.round(eWidth2) );

Despite my efforts, there always seems to be a slight height discrepancy. Does anyone have a viable solution?

Answer №1

Have you considered using the CSS property overflow:hidden to trim off a few pixels and hide some of the edges on your element?

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 PHP implementation of Google reCAPTCHA is malfunctioning when combined with AJAX

I have a form on 100.php that makes an AJAX call to 200.php. <html> <head> <!-- Include the reCAPTCHA API JavaScript library provided by Google --> <script src='https://www.google.com/recaptcha/api.js'></script ...

displaying the JSON output from a PHP script within an HTML table

Here's the scenario: I have an HTML file that involves the following steps: Accepts a card number input from the user using an HTML form, Sends this input to a PHP file and receives a JSON-formatted response through xmlhttp.responseText, Needs to di ...

Changing the color of an image with a click event in HTML

My coding dilemma involves two HTML codes: one displaying a table with grey square buttons, and the other featuring the same table but with orange buttons instead. I am looking for a way to change the color of the button from grey to orange when clicked, ...

JavaScript array with more than 4 elements

I am working on a program where I have created an array and now want to display all the words that contain more than 4 letters. Check out my code snippet below: function oppC(){ var ord = ["Apple", "Two", "Yesterday", "mother", "lol", "car", "co ...

What are the steps to clipping a canvas using CSS clip-path?

When it comes to clipping a canvas, there are multiple methods that can be used. One way is to create a path with getContext('2d') and set globalCompositeOperation. Another method involves using -webkit-clip-path or clip-path, though the latter m ...

Table for maximizing space within a cell (Internet Explorer 8)

I am attempting to make the "innerTable" fill up all available space within another table. The issue is with IE8 (no compatibility mode, IE8 browser mode, Doc mode IE8 Standards). The table does not expand to fit the containing TD. I tried enclosing the ta ...

The lua.vm.js ajax callbacks are triggering, but unfortunately, the requested data is not

After raising this issue at https://github.com/kripken/lua.vm.js/issues/5, I realized that submitting it to stackoverflow might yield a faster response due to higher exposure. To ensure clarity, I will restate my question: How can the callback data be acce ...

Design a collection of image icons to use as a toolbar in a web

I am in the process of creating a basic online application that allows users to select images from a toolbar (or storage box) and drag them onto a canvas. I am relatively new to web development but have figured out the drag and drop functionality. Right no ...

What is the best way to design a white arrow with a subtle touch of grey outlining?

Question: I am interested in creating a left-pointing arrow with a grey border. Currently, I have only managed to create a grey arrow without a border. Is there any way I can achieve this? Attached is a picture to illustrate what I'm looking for. An ...

Popup mode is utilized by CodeIgniter error pages to display error messages

Is there a way to show error messages without being redirected to the error pages located in application\errors\*error_pages*? We want to remain on the same page and display any errors that occur in a popup. Can someone provide an example code fo ...

Using jQuery, you can retrieve data from a specific sheet in Google Sheets API by executing a

Is there a way to access cells from different sheets within a Google spreadsheet? Currently, I am able to access a range of cells from the default first sheet using the following code: var url = 'https://docs.google.com/spreadsheets/d/' + spread ...

The continuous launching of a loop with jquery setTimeout just doesn't seem to stop

I'm facing an issue with my Ajax request that I need to trigger every 5 seconds to check if a particular process has completed. I've attempted to use setTimeout() for this purpose, but the requests are being launched continuously without adhering ...

What is the most optimal jQuery code to use?

Just wondering, which of the following code snippets is more efficient (or if neither, what would be the best way to approach this)? Background - I am working on creating a small image carousel and the code in question pertains to the controls (previous, ...

Retrieving an element based on user input's value

Having trouble comparing multiple input elements to another input by matching values. The problem arises when attempting to match values with user input on the page load, unlike when the inputs already have values. Check out the JSFIDDLE here <script ...

Having trouble getting the JavaScript function to run when clicking a button inside a div or form?

Hey there, so I've got this scenario where I have a button nestled within a div. Take a look at the HTML snippet below: <div class="row"> <button type="button" id="submit">Send</button> </div> Prior to this button, there ...

CSS: Concealing a separate div

I am working with a parent div in my code that has 2 child divs. I am hoping to find a way to hide the second child when hovering over the first child, using only CSS or JavaScript. Take a look at my Fiddle here <div class="parrent"> <div id ...

What could be causing the append function to only work during the final iteration of my code?

I find myself in the position of recreating a table based on another existing one. While I am aware that this may not be the ideal approach, it is a task that has been assigned to me rather than being my own choice. My method involves iterating through ea ...

Adding a class to a TD element only when there is text in that TD as well as in other TD elements

I am facing a challenge where I need to add a new class to a td element, specifically the first one in the code snippet below. However, this should only happen if that td contains a certain number (e.g., "2") and if the next td contains some specific text ...

Troubining CSS nth-of-type or child selectors with custom elements within additional custom elements may cause unexpected behavior

Struggling with CSS :nth-child and creating a unique layout with custom elements inside custom elements. The issue arises when trying to display different icons using the :before pseudo-element, but all icons end up being the same. Below is the code snippe ...

A complete guide on utilizing *ngFor in Angular to display data rows

I am facing an issue with using *ngFor to create new "rows" for adding new categories dynamically. Although there are no errors displayed when I run the program, the intended functionality is not achieved. I have tried making some modifications but it see ...