What is the most effective way to line up three square images, with one being larger than the other two, and positioning the larger one to the left of the two smaller ones stacked on top of each other?

Currently, I am struggling with arranging three square images on a webpage. The larger image should measure 800 x 800 pixels and be positioned to the left, while the two smaller images, each measuring 400 x 400 pixels, should stack vertically to the right of the larger image.

To give you a better understanding, here is an illustration:

https://i.sstatic.net/Ocspo.jpg

The HTML code using Bootstrap 4 that I have implemented looks like this:

<div class="container">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-7">
                <img src="modernforms/src/img/main.jpg" width=700 height=700 />
            </div>
            <div class="col-lg-5">
                <img src="modernforms/src/img/side.jpg" width=350 height=350 />
                <img src="modernforms/src/img/sidetwo.jpg" width="350" height="350" />
            </div>
        </div>
    </div>

However, my main challenge lies in ensuring that this layout remains user-friendly when viewed on mobile devices. Ideally, I would like the squares to become full width col-12, stacking on top of one another, but I am unable to achieve this effect. Is there a misunderstanding on my part, or is it simply impossible? Any guidance would be greatly appreciated. Thank you.

Answer №1

To create a layout with one row containing 2 columns, you can nest another row in the second column with two images each taking up the full width. It's recommended to remove the width and height attributes from the images and rely on the col classes for sizing. Additionally, consider adding img-fluid class to the image for better resizing.

<div class="row">

 <div class="col-12 col-lg-7">
   <img src="big picture here" />
 </div>

 <div class="col-12 col-lg-5">
   <div class="row">

     <div class="col-12">
       <img src="small image 1 here"/>
     </div>
     <div class="col-12">
       <img src="small image 2 here"/>
     </div>

   </div> <!-- end of nested row-->
  </div>
</div> <!-- end of main row --> 

Answer №2

If you're looking to simplify your design by removing some of the complexity of Bootstrap, you can achieve this easily using CSS grid. For example, creating a 2x2 grid where the first image spans two rows while the others only occupy one row for the desktop version.

For mobile, simply adjust the grid structure to 1x1 so that all images are stacked vertically. Here's an example:

body{
  margin: 0;
  overflow-y: auto;
  height: 100vh;

  --grid-columns: 1fr 1fr;
  --grid-rows: 1fr 1fr;
}

img{
  height: 100%;
  width: 100%;
  object-fit: cover;
  min-height: 300px;
}

.grid-container{
  height: 100%;
  display: grid;
  grid-template-rows: var(--grid-rows);
  grid-template-columns: var(--grid-columns);
}

.big-img{
  grid-row: span 2;
  grid-column: 1;
}

@media only screen and (max-width: 768px) {
  body {
    --grid-columns: 1fr;
    --grid-rows: 1fr;
  }
}
<div class="grid-container">
      <img class="big-img" src="https://images.pexels.com/photos/1133957/pexels-photo-1133957.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="">
      <img src="https://www.thewowstyle.com/wp-content/uploads/2015/02/Beautiful-Wallpapers-14.jpg" alt="">
      <img src="https://thumbs.dreamstime.com/b/beautiful-dandelion-flower-flying-feathers-colorful-bokeh-background-macro-shot-summer-nature-scene-beautiful-dandelion-147400154.jpg" alt="">
  </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

The margin-left and margin-right in HTML CSS are not cooperating to center a div

I'm currently diving into the world of CSS and HTML, but I've hit a roadblock. The margin-left and margin-right in the ".logo" div class are refusing to center the div as expected. Despite conducting research and meticulously checking over the co ...

Nuxt.js implemented with Auth using jwt refresh tokens

I've implemented the Auth library in my Vue/Nuxt project and have successfully set up JWT Authentication. However, I'm encountering an issue with the refresh token. The refreshToken cookie is consistently being set to null: https://i.sstatic.ne ...

When jQuery fails to detach() due to the presence of an input tag

I have a situation where I am trying to rearrange elements within a table. Everything works fine, until I introduce a tag, which triggers this error message:</p> <pre><code>Error: this.visualElement is undefined Source File: http://192. ...

Is it possible for me to connect one element to another using CSS or JavaScript?

On my website, there are three columns of interactive elements that can be scrolled vertically. Users are able to select one item from each column, and once selected, the chosen elements are connected by lines. The challenge I am facing is determining ho ...

Tips for updating the css class for multiple DOM elements using jQuery

I am currently attempting to modify the class property of a specific DOM element (in this case, a label tag) using jQuery version 1.10.2. Here is the code snippet I have written: var MyNameSpace = MyNameSpace || {}; MyNameSpace.enableDisableLabels = (f ...

What is the best way to send an email with a randomly generated HTML output using a <button>?

I am currently working on a feature where a random HTML output is sent to me via email whenever a user clicks on a button on the website page. The user receives a code when they click the button, and I want that code to be emailed to my address automatical ...

Navigate to the specific page using the router-link with the designated path

I have 10 different filters displayed in a table and I want each filter name to link to a specific page. Here is an example of my table row: <md-table-row v-for="(row, index) in manage" :key="index"> In the first cell of the table, I'm trying ...

The function view() is not displaying the CSS and JS files properly

Having trouble with loading the css and js on my view: This is how I set up the controller: return view('home.news') ->with("news", $news); And here's how the route is defined: Route::get('/news/{id}&apos ...

PHP failing to forward HTML form responses via email

I have uploaded this PHP file on the server and I am trying to get user responses from the HTML form within the PHP file to be sent to a specified email address. However, for some reason, the responses are not being successfully delivered to the email ad ...

Troubleshooting HTML Output Display Issues

I've been trying to post my content exactly as I submit it, but for some reason, it's not working. When I enter two paragraphs in a post, the output doesn't maintain that formatting. Instead, it removes the paragraph breaks and displays the ...

Do not trigger mouseleave events when absolute positioned elements have overlapping layers

I am facing a challenge with a table that includes multiple rows that need to be editable and deletable. To achieve this, I have created a <div> containing buttons that should appear when hovering over the rows. While this setup works well, I am enco ...

Add a variety of images

Looking for help with uploading multiple images to a folder and saving paths in the database? Here's a code snippet I've been working on: The issue I'm facing is that while the image names are being saved in the database, the actual images ...

Tips for utilizing the JQuery feature to clear input text

After attempting to use onfocus and onblur attributes within the input tag to clear input text, I discovered a JQuery function that should do the trick for me. However, I am encountering issues with getting it to work across multiple fields. $('.defa ...

The menu shifts the remaining parts of the page downwards as it expands

Is there a way to prevent my menu from impacting the code below it? I have considered using position:fixed; to address this issue, but I am not entirely certain. Here is the jsFiddle link for reference: http://jsfiddle.net/chaddly/u9EEt/#base ...

What are the best techniques for resizing a bar graph column to perfectly and proportionally match its container size?

Creating a basic bar chart library using vanilla JS and jQuery is what I'm working on. The code below is functional: var userData = { 'Black': 8, 'Latino': 6, 'Native': 4, 'Asian': 10, 'White': 12, & ...

Scrape embedded content within an IFrame on a webpage with Java

Currently, I am interested in crawling the dynamic content within an IFramed webpage; Unfortunately, none of the crawlers I have tested so far (Aperture, Crawl4j) seem to support this feature. The result I typically get is: <iframe id="template_cont ...

Problem with Bootstrap 4 layout in Firefox - works fine, but not displaying correctly in

Hey everyone, I've encountered an issue with my code. It's working perfectly fine in Firefox, but in Chrome and Opera, the layout is all messed up. Can anyone help me pinpoint what might be going wrong here? <div class="row broadband-block"&g ...

Design the title attribute for the style area tag

Currently, I have set up an image with various clickable areas on it, and I want to display a description when the user hovers over these areas. My current solution involves adding the descriptions as titles, but I feel like there might be a better way to ...

Adding a .PHP File to Two Separate DIVs

I am using wordpress to create a custom theme. I'm interested in placing all the content from my slider.php file inside a div box on my index.php page. How would I go about doing this? SLIDER.PHP <div class="slider"> // All the image tags wit ...

Display the closing tag depending on specific conditions to simulate the behavior of a calendar

Is it possible to conditionally render a closing tag using v-if? If so, what is the correct way to do it? Initially, I tried the following: <template v-for="day in days"> <td class="days">{{day.number}}</td> <template v-if ...