What is the best way to ensure these dual-layered images are responsive on mobile devices?

I am struggling to make these two images responsive on mobile view using CSS. I can't seem to figure it out, and it's really frustrating me.

What I'm trying to achieve is to have the two images not directly on top of each other, but rather one slightly overlapped on the other. It's hard to explain, but I hope someone can assist me in solving this issue.

.content__stacking {
  display: flex;
  width: 100%;
  justify-content: center;
}

.stacking1 {
  height: 370px;
  width: 100%;
  position: relative;
  background-color: #fbf9f6;
  padding-left: 5px;
}

.stacking2 {
  position: absolute;
  z-index: 1;
  left: 1050px;
  top: 100px;
  width: 100%;
}

.parent {
  position: relative;
  /*top: -220px;
  left: -900px;*/
}

.image1 {
  position: relative;
  top: -20px;
  left: -20px;
  border: 1px solid #000000;
}

.image2 {
  position: absolute;
  top: 100px;
  left: 100px;
  border: 1px solid #000000;
}
<div class="content__stacking">
  <div class="stacking1">
    <div class="stacking2">
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
        <br>Quos natus, corrupti vitae assumenda veritatis consectetur
        <br>debitis corporis ex odit iste voluptates rerum omnis animi ullam itaque.
        <br>Quis quam facilis facere?</p>
      <br>
      <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.
        <br>Sunt unde reiciendis quod deserunt officia quos consequatur laborum ea amet quo.</p>
    </div>
  </div>
  <div class="parent">
    <img class="image1 img-responsive" src="https://placekitten.com/200/300" alt="">
    <img class="image2 img-responsive" src="https://placekitten.com/200/300" alt="">
  </div>
</div>

Answer №1

Here is a solution that should fulfill your requirements: https://stackblitz.com/edit/web-platform-fd3nde?file=index.html

.main-container {
        display: flex;
        height: 370px;
        width: 100%;
        position: relative;
        background-color: #fbf9f6;
        padding-left: 5px;
    }

    .text-container {
        margin: 10px;
    }

    .image-container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 350px;
        min-width: 10px;
    }

    .image2 {
        margin: 100px 0 0 -150px;
    }
<div class="main-container">
<div class="text-container">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
        <br>Quos natus, corrupti vitae assumenda veritatis consectetur
        <br>debitis corporis ex odit iste voluptates rerum omnis animi ullam itaque.
        <br>Quis quam facilis facere?</p>
    <br>
    <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.
        <br>Sunt unde reiciendis quod deserunt officia quos consequatur laborum ea amet quo.</p>
</div>
<div class="image-container">
    <img class="image1" src="https://placekitten.com/200/300" alt="">
    <img class="image2" src="https://placekitten.com/200/300" alt="">
</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

Are you searching for the origin of a dynamic dropdown widget or database?

Currently, I am browsing through and I have a query regarding accessing all available classes/options for the courses in a semester. There is a class locator on the top left of the page with a dynamic drop-down menu. Can anyone suggest how I can access ...

Utilizing the optimal method for aligning text to either the right or left side

I am currently working on creating a container element with multiple child elements. I would like these elements to be aligned differently, some left-aligned and others right-aligned. This includes scenarios where the child elements themselves are containe ...

In JavaScript, the gallery feature with Lightbox effect creates a unique touch as only half of the screen fades to black in

Hello everyone, I'm a complete beginner when it comes to programming so please be gentle with me on my first question :) I'm trying to put together a simple website with a lightbox gallery, and you can check out what I have so far here. The prob ...

Is there a table that allows users to input percentages?

Looking for help with a table that has 2 columns: "Activities" and "Average % of Time". Users need to input a % value for each activity in the "Average % of Time" column. There are 7 rows for activities. The goal is to ensure that the sum of the % values f ...

What is the best way to darken the background when an alert is displayed and disable the dimming effect when the alert is closed?

Here's the JavaScript snippet I'm using: reset.addEventListener("click", function(){ document.querySelector("#body").classList.add("darkenPage"); myReset(); alert("Reset Successful!!"); document.querySelector("#body").classList.re ...

``Why Ionic 3 Popover Sizes Should Adapt to Different Screen

Currently in my Ionic 3 project, I am utilizing a popover with a set height using the following code snippet: editOpty(rw){ let popover = this.editOptyPopup.create(EditOptyPopoverComponent, rw, { cssClass: 'edit-opty-popover'}); popover ...

Struggling to figure out the best way to showcase Python code within an HTML document

Hello there, I am in the process of developing a website to showcase past year questions from the competitive exam JEE in India. To gather the questions and respective options, I utilized bs4 and requests for web scraping from ExamSide, a website that hous ...

I am looking to create buttons that can switch between two different styles of a specific element, like an h1 tag, when clicked. However, instead of toggling

//In this HTML document, I am trying to achieve a functionality where my buttons can toggle the style of an h1 element between the colors yellow and purple when clicked. However, I have encountered an issue where the buttons disappear during a transition ...

Replacing HTML text with JSON data can be easily achieved by using JavaScript

After receiving data from an API and converting it into JSON format, I encountered difficulty when attempting to change a selected element in HTML. Every time I tried to do so, I either got 'undefined' or 'Object Object' as the output. ...

Conceal the column title for order items in the WooCommerce admin panel

I've been attempting to hide certain columns within the administrative section of Woocommerce, but have had no success with the code I'm using. I'm currently stuck and my question is: Is there a way for me to conceal specific column names i ...

Ensuring all my input fields are uniform in size on the left side

Hey there! I am currently working on some input fields that have a left and right side. The left side serves as a label while the right side contains the corresponding data. One challenge I am facing is that the left sides of the fields vary in size based ...

Insert PDF to completely fill the screen

Seeking advice on embedding a PDF in an HTML document with a consistent height of 100%. The challenge lies in the varying height of the PDF, and the need for the layout to adapt accordingly. ...

Angular 7 with a transparent background on the first division tag

I have searched for answers related to this topic, but so far I have not found any that are valid Currently, I am utilizing Angular 7 as my Framework and running into a particular issue. The components I have are: - Header - Landing app.component.html ...

A method for altering the values of HTML form checkboxes by toggling between checked and unchecked states, followed by transferring those values to the clipboard

Hello everyone, I'm new to coding and seeking some assistance with a problem I've encountered. My goal is to create a multi-input form with checkboxes, allow the user (me) to fill it out, and then click a "copy" button to transfer the values to t ...

Interactive Sideways Navigation Bar

showcases a sleek horizontal scrolling menu on mobile devices. I aim to replicate this functionality for a website I'm redesigning that features extensive navigation elements. Key Features: Left and right scroll button options Centered list item op ...

What are some effective ways to manage repetitive HTML elements like headers and footers in Angular 4?

Within my Angular web project, I find myself using a variety of different headers on multiple pages. Is there a way to streamline this process by coding the header and footer once and having them automatically included in one or more pages? I am looking ...

Having a challenge with aligning a form in a view, as neither bootstrap nor plain CSS seem to be helping with centering it correctly

What techniques can I use to center this form properly in both bootstrap and plain CSS? So far, I have been able to center some parts of it, but when I try to center others, they shrink and create a mess. When I use bootstrap to center the elements, they b ...

Achieving an italicized appearance throughout an HTML document

I recently downloaded a sample page from the Mathjax website and acquired their package from Github to use it locally. In addition, I wanted to incorporate the computer modern font, so I unzipped the file containing ttf files into fonts/cmu. Here's ...

What does the client perceive or not perceive? Node.js, JavaScript, MySQL

For a university project, I am tasked with creating a web application that is compatible with both desktop browsers and mobile devices. The technologies I will be using include HTML, CSS, JavaScript, Node.js, and MySQL. I have recently familiarized myself ...

Is there an issue with this piece of jQuery code?

function updateFieldFromUrl(url, param, field) { var anchor = document.createElement('a'), query; anchor.href = url; query = anchor.search.replace('?', '').split('&'); for(var i = 0, keyValue; i < qu ...