Stacking pictures with CSS and absolute placement

I have designed a webpage where I need to layer three images in a specific order to create a background for content placement without any movement during scrolling. Fixed positioning is not suitable for this purpose. Below is the sequence in which the images should appear, from back to front (1-3):

  1. sky.jpg - Background image
  2. backDrop.png - Positioned above sky.jpg
  3. BtmRight.png - Intended to be positioned above all other images at the bottom right corner
Both backDrop.png and BtmRight.png are set with absolute positioning and respective z-index values to establish their display order. However, I am facing difficulties in displaying the BtmRight.png image at the bottom right corner above all other images. I want this image to stay in place while scrolling the page, allowing content to be displayed over all images. Below is a snippet of my HTML/CSS code. Any guidance or support on this matter would be highly appreciated. Thank you.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<style type="text/css">
html {
  height: 100%;
  margin: 0;
  padding: 0;
  margin-top:100px;
  background: url(sky.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
   background-size: cover;
}
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
#imgBack {
    width: 100%;
    margin-top:100px;
    position:absolute;
    z-index:20;
    border:#0FF thin solid;
}
#imgBtmRight {
    position:absolute; 
    z-index:50; 
    bottom:0; 
    right:0;
}
</style>

<body>

<img id="imgBtmRight" src="BtmRight.png" width="413" height="283" /> 

<img id="imgBack" src="backDrop.png" />

</body>
</html>

If you can shed some light on this issue or provide assistance, it would be greatly appreciated. Thank you.

Answer №1

Ensuring your DOM elements are stacked in the correct order is essential (don't forget to close that div):

  1. body
  2. Backdrop
  3. BtmRight
  4. Content

In the natural 'stacking' process, think of each element (image, div, etc.) as a piece of paper. As you progress down the HTML document, you are adding pieces of paper to the stack. These papers lay on top of each other, unless the z-index is explicitly changed - but it's always best to have them in the correct order from the beginning.

Edit:

It seems to be functioning properly:

Here's an example using linked images

The only modifications I made were the image sources and positioning on the body tag. Unless there's something else missing from the code, you shouldn't encounter any issues.

ANOTHER Edit:

If you want the bottom-right image to remain fixed in place, utilize position: fixed for that image instead of position: absolute.

YET ANOTHER Edit:

To ensure the content appears over the bottom-right image, simply create a wrapper for your content and use z-indexing:

Take a look at this example

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

What is the best way to align the Storefront Menu in the center?

If you want to reproduce the issue I'm facing, visit the demo page of the storefront here: then remove the node <ul id="site-header-cart" class="site-header-cart menu"></ul> that contains the cart box (located next to the menu) so that on ...

Refresh all fields for various products with a single click of a button

Our Magento multi-vendor site allows vendors to easily manage their products. For each single product, vendors can view and update information such as price, selling price, quantity, and more from their vendor account. We have implemented a feature where ...

Is it possible for a Bootstrap modal dialog to overlay another dialog window?

<button class="btn" onClick="$('#firstModal').modal('show');">Click Here</button> <!-- Modal --> <div id="firstModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden=" ...

In React, the Textarea component that displays the character count only updates its value after a page reload

Contained within this element is the following component: import React, { useEffect, useState } from 'react'; import { TextareaTestIds } from '../utils/test-ids'; export interface TexareaProps extends React.TextareaHTMLAttributes<H ...

The card-group is off-center within the column

I am facing a challenge with the alignment of 3 cards within a card-group that are contained in a div with the col class, which is wrapped by a div with the row class, all within a div with the container class. Currently, the cards are not centered. I hav ...

Conditional Statements in jQuery

Trying to implement a check for the CSS 'display' property being set to "none", then slideDown the element "menuBK". If not, slideUp "menuBK" but encountering an error in my IF statement. $(document).ready(function(){ $("#burger").click(func ...

Tips for adjusting the initial scale to ensure your mobile website fits perfectly on the screen

I'm trying to figure out the best way to adjust the 'initial-scale' so that my website's width fits perfectly on any device screen when first loaded. Check out my website here: While it looks fine on regular browsers, I had some issue ...

Reduce the height of the tabs bar in the Gnome terminal

After recently installing Lubuntu 16.04 with gnome-terminal, I noticed that the terminal takes up more space on my monitor due to two unnecessary buttons in the top right corner. For avid terminal users like myself, these buttons only add bulk to the tabs ...

Transform the binary image data sent by the server into an <img> element without using base64 encoding

It's been a challenge trying to find a reliable method for adding custom request headers to img src, so I'm experimenting with manually downloading the image using ajax. Here is an example of the code I am working on: const load = async () => ...

Access the hyperlink contained within the table

Having trouble clicking a navigation link inside a table? I've tried: getElementByID getElementsByClassName getElementsByTagName but none seem to be working. When using the following code: Set tbls = HTMLDoc.getElementByID("tabToggleTable") it r ...

AJAX - Implementing a delay in displaying AJAX results

My search function uses AJAX to retrieve data from the web-server, and I am trying to implement a fade-in animation for each search result. I want the results to load and fade in one by one with a slight delay between them. Currently, it seems like all th ...

Steps to Retrieve and Showcase a Compilation of YouTube Clips with JavaScript

Recently, I managed to write a C code that retrieves the list of YouTube videos from the URL "*http://gdata.youtube.com/feeds/api/standardfeeds/top_rated*" using the libsoup library. By utilizing libxml2, I was able to parse the XML data and extract specif ...

An error occurred: TypeError - Unable to access the 'value' property of a null object during a value change

Example ImageCreating a dynamic form where rows and select box options are added dynamically using 'x' and 'i' increment values in two JavaScript functions. The code works fine when the option selected is 0.5, but throws an error Uncaug ...

css center arrow-aligned underline text

Trying to emphasize my text with an additional arrow centered on the line is proving to be a challenge. When attempting this, the text does not align in the center of the page. .souligne { line-height: 17px; padding-bottom: 15px; text-transform: u ...

React app version displaying incorrect links to CSS and JS files

I have been immersed in a React project called Simple-portfolio, you can find the GitHub repository here: https://github.com/Devang47/simple-portfolio and the live site at this URL: While everything works smoothly on the development server, I encountered ...

What is the best way to integrate a vh property instead of px for a scrolling navigation using jQuery?

I want to achieve a navigation bar that fades in after scrolling 100% of the viewport height, but all examples I find use a pixel value instead of viewport height. Is there a way to convert window height into jQuery to make this work? Thank you in advance ...

Space between flex content and border increases on hover and focus effects

My code can be found at this link: https://jsfiddle.net/walshgiarrusso/dmp4c5f3/5/ Code Snippet in HTML <body onload="resize(); resizeEnd();"> <div style="margin: 0% 13.85%; width 72.3%; border-bottom:1px solid gray;"><spanstyle="visibilit ...

Ways to crop a background image from the bottom left and right using CSS

I'm attempting to replicate the background image found at https://i.stack.imgur.com/nYDet.jpg My attempts to use clip-art on this image have been unsuccessful in achieving that shape. .hero-section { height: 740px; background: linear-gradient( ...

I am in search of a JavaScript or jQuery plugin for an HTML slider with a unique range functionality

I've been searching online but couldn't find a slider like the one shown in the attachment. Can anyone help? Is there a way to create this specific slider or is there an existing plugin or library for it? Please refer to the image below : ...

What is the best way to change the "MuiPaper-elevation1" attribute in a Card element within Material-UI?

My Card component in HTML looks like this: <div class="MuiPaper-root MuiCard-root makeStyles-Card-5 MuiPaper-elevation1 MuiPaper-rounded"> I want to change MuiPaper-elevation1 to MuiPaper-elevation0 to remove the shadow. I attempted: ...