Different sized image grid display

Could you please take a look at this screenshot:

I am facing an issue with the grid layout. The first image in the grid is too short, which results in a big gap between the upper left and lower left pictures. Here is what it looks like currently:

Is there a way to have the grid rows adjust based on the height of the picture, similar to the layout in the first image? It also needs to be responsive. Additionally, how should I position the third picture so that it doesn't align with the first two? Can this be achieved using margins?

I have been struggling with this for a few days now, initially with flexbox and now with grid, but haven't been able to get the desired result. Here's the relevant CSS and HTML:

.fourth {
    display: flex;
    flex-direction: column;
    align-items: center;

}

.collage2 {
    display: grid;
    width: 85%;
    grid-auto-columns: repeat (2, 1fr);
  
   
}

.collage2 > img {
    object-fit: cover;
    width: 100%;
    max-height: 100%;
}

.collage2 img:nth-child(3) {
    grid-row: 1/2;
    grid-column: 2;
  
}
<section class="fourth">
           
                <div class="collage2">
                    <img src="/images/photo-3.jpg" alt="Man drawing on whiteboard">
                    <img src="/images/photo-4.jpg" alt="Ableton address on a brick wall">
                    <img src="/images/photo-5.jpg" alt="Man and woman working at a music studio">
</div>

Answer №1

Recently experimented with some code on Codepen, and I believe it could serve as a good starting point for you: Check it out here

<div class="grid">
  <img src='https://images.unsplash.com/photo-1666880147941-b145c43cfe6b?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2Njg2ODQxMDk&ixlib=rb-4.0.3&q=80' alt=''>
  <img src='https://images.unsplash.com/photo-1667489022797-ab608913feeb?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2Njg2ODQxMDk&ixlib=rb-4.0.3&q=80' alt=''>
  <img src='https://images.unsplash.com/photo-1593875460489-aa913d8a0fe2?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2Njg2ODQxNjk&ixlib=rb-4.0.3&q=80' alt=''>
</div>
img {
  width: 100%;
  object-fit: cover;
}
.grid {
  --gap: 8%;
  display: grid;
  align-items: center;
  justify-items: center;
  grid-template-columns: 2fr 3fr;
  gap: var(--gap);
  padding: var(--gap);
  position: relative;
}

img:nth-of-type(2) {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

img:nth-of-type(3) {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  height: 80%;
}

.grid::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: calc(2 / 5 * 100% + var(--gap) * 2);
  bottom: 0;
  background: lightseagreen;
  z-index: -1;
}

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 incessant ascent of the div to the page's peak leaves me perplexed as to the cause

While trying to set up my website template from , I noticed that the main div, which includes circles and a call to action at the bottom, keeps aligning with the top of the page and under the navigation bar. Any ideas on what could be causing this issue? ...

"Explore the possibilities with Flask and Bootstrap - multiple collapsibles that reveal hidden content, each one revealing a unique experience as

I created an HTML page that showcases a database filled with emails. Each email is displayed in a collapsible format, where the timestamp triggers the collapse and reveals the content of the email. Here's how the HTML page is structured: {% extends " ...

Creating a multi-column ordered list that spans multiple pages is a great way to organize and

My goal is to showcase a numbered list in a three-column format, following the guidelines presented in this particular query. However, I am looking to maintain the continuity of the list across different pages by ensuring that the subsequent item on the ...

Creating a sticky section with Tailwind CSS utility classes

I have a page in my Next.js web app, and I want to make the section highlighted in blue (wrapped in <aside> tag) sticky so that it stays in place while scrolling, with only the main section containing the chart scrolling. The code snippet below is f ...

Mandate that users select from the available place autocomplete suggestions exclusively

I have integrated the "Places" Google API to enable address autocomplete in an input field on my website. However, since the service is limited to a specific area, I have implemented an autocomplete filter. The issue I'm facing is that users are stil ...

What is the best way to include a variable or literal as a value in styled components?

When it comes to managing various use cases, I always rely on props. However, I am currently facing a challenge in changing the border color of a styled input during its focus state. Is there a way to utilize props for this specific scenario? Despite my f ...

What steps should be taken to address the issue when the .media$thumbnail.url cannot be located

Creating a custom widget for bloggers <script type="text/javascript"> function mycallback(jsonData) { for (var i = 0; i < jsonData.feed.entry.length; i++) { for (var j = 0; j < jsonData.feed.entry[i].link.length; j++) { ...

Child Theme setup in progress! Beware of the error message: "Unable to access file: file_get_contents9(). The specified stream does not exist."

I am currently in the process of developing a child theme based on my existing theme (Tesseract 2). I have carefully followed the guidelines outlined here, but unfortunately, I keep encountering the following error: Warning: file_get_contents(/home/fletch ...

utilizing ng-option to present choices in a dropdown menu

I have been implementing a scroll-down menu in my application using options. However, I now want to switch to using ng-option to populate the values from a JavaScript file. I also require assistance with writing AngularJS code for this task. Below is a s ...

Utilizing the input type file within an anchor tag to create a dropdown item

I am facing an issue while trying to incorporate the input type file within a dropdown item inside an anchor tag. Here is the code snippet causing the problem: <div className="dropdown-menu actions-text"> <a className="dropdown-item" href= ...

Conceal specific pages within the DataTable without deleting them

Currently, I am facing an issue where the dataTable paginates and removes the DOM pages along with the data. My goal is to extract all the data from the dataTable and convert it to JSON without losing access to the DOM when pagination occurs. I want to m ...

Two problems encountered with the scroll bar feature on a tabular display

Have 2 inquiries about the table displayed below: Question 1: The height of the table is set to 500px, but I am puzzled by the fact that it seems like the content below, which is not part of the table, appears within the table due to the scroll bar exten ...

Random Image Generator in Javascript with Links

I am attempting to load one image at a time along with its corresponding link. My goal is to display the image in a div with an ID of 'ads'. Here is the code I have so far, but I am not proficient enough in JavaScript to achieve my desired outcom ...

Having trouble viewing the image slider on an HTML webpage

I've been attempting to incorporate an image slider into my personal website on GitHub, but I've encountered some difficulties as the images are not displaying. Interestingly, I can load individual images without using the slider and they show up ...

When floated to the right, the element is being pushed onto the next line in Firefox

Within a div, there are four elements. I specifically want the last element to be positioned on the far right, so I applied float: right to it. However, in Firefox, the last element gets pushed to the end of the next line instead. This issue does not occ ...

Using the Strikethrough Feature in React

Is it possible to apply a strikethrough effect to a checkbox's label text when toggled on and off? In my system development process, I've utilized various methods. What modifications should be made in the fComplete method for this feature to wor ...

Recreate body content with JQuery Mobile

I've been attempting to duplicate the entire HTML content within the tags. However, even though the appearance on screen is correct, none of the links are functioning.</p> <p>To view the fiddle, click here: [Here is a fiddle][1]</p> ...

Creating a dynamic page footer for a PDF document using Rotativa's content generation capabilities

As I work on generating a PDF, my employer has requested that I add a footer to each page of the document. Currently, the PDF is being created using Rotativa, where an HTML page is converted into a PDF. However, I am facing a challenge in determining the ...

Troubleshooting my PHP MSQL Update function in CRUD operations

Having trouble with the Update function when trying to implement CRUD on my website. Can anyone assist me? I can successfully Create, Read and Delete, but updating is giving me issues especially for Admin users. Below is the code snippet: <?php // Inc ...

Ways to vertically center an absolutely positioned element

In the code snippet below, there is a .square-container that is absolutely positioned and contains a square. The goal is to vertically center the .square-container within its parent div. .container { position: relative; background-color: blue; } ...