Is there a way to stack overlapping divs in a layout that resembles a pile of papers?

I am trying to create a layered effect with multiple divs, where each div is positioned slightly up and to the left of the previous one, giving the appearance of a stack of papers. I have experimented with absolute positioning and z-index, but I'm having trouble getting the positioning just right. You can view my attempts on this Fiddle

.box{
  width:100px;
  height:100px;
  border-style:solid;
  border-color: #D3D3D3;
  position:absolute;
}

.first{
  background-color:yellow;
  z-index:10;
  bottom:0;
  right:0;
}

.second{
  background-color:blue;
  z-index:9;
  bottom:10;
  right:10;
}

.third{
  background-color:red;
  z-index:8;
  bottom:20;
  right:20;
}

.background{
  height:100%;
  background-color:green;
  position:relative;
  z-index:0;
}

.container{
  border-style:solid;
  border-color:black;
  width:300px;
  height:300px;
  position:relative  
}
<div class="background">
  <div class="container">
    <div class="box first"></div>
    <div class="box second"></div>
    <div class="box third"></div>
  </div>
</div>

Answer №1

When setting positions in CSS, it is important to include a unit of measurement. For example, instead of using bottom: 10;, you should use bottom: 10px;

Adding the px ensures proper functionality.

Answer №2

I checked out your JSFiddle... Does this match the result you were aiming for? https://jsfiddle.net/aewwq1np/

I aligned each element to the same position and then adjusted their placement using margin-top and margin-left

To enhance the appearance, I incorporated some box shadow effects for added dimension. Here's a tool I used to experiment with different box shadow styles:

For example:

.second {
  bottom:10px;
  right:10px;
  margin-top: 20px;
  margin-left:4px;
  -webkit-box-shadow: -2px -12px 61px -9px rgba(0,0,0,0.75);
  -moz-box-shadow: -2px -12px 61px -9px rgba(0,0,0,0.75);
  box-shadow: -2px -12px 61px -9px rgba(0,0,0,0.75);
}

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

Tips for incorporating Bootstrap classes into a React project, setting the className attribute to an empty string

After setting up Bootstrap and Create-React-App using npm on my local machine, I proceeded to create a new React app. The first component I worked on was counter.jsx: import React, { Component } from 'react'; class Counter extends Component { ...

Varying Heights on Different Pages

I have encountered a styling issue while using md-card in my application. The problem arises when I also include md-autocomplete in the home page, requiring me to modify the angular-material.css for proper display. However, on the product page where I uti ...

The presence of Bootstrap remains hidden unless space is designated for it

Question about Bootstrap 5.1.3: Is there a way to hide elements on a page using the bootstrap class ".invisible" without allocating space for them? Currently, when the elements are set to visible using the class ".visible", they occupy space on the page ...

Tips on navigating the scroller vertically as the user interacts with a selected div by scrolling up and down

On my webpage, I have various div elements displayed. Each div has the options to move it up or down using the buttons labeled "UP" and "Down". When a user selects a div, they can then use these buttons to adjust its position. I am looking for a way to au ...

Utilizing flexbox to create spacing between elements and ensuring there are no margins on the parent

Discover a Codesandbox demo at: https://codesandbox.io/embed/silly-firefly-87cov A unique challenge awaits with this project - elements within the parent container are positioned dynamically using flexbox. But how can we apply margins selectively only bet ...

What mistakes have I made in this CSS code?

Check out the REQUEST FORM in the image below (with a green background). It is currently aligned at the top, but I would like it to be centered vertically. https://i.sstatic.net/4A6Tw.jpg This is the CSS style being used, .rtitle { background-color: Gre ...

Center two elements within a div container both horizontally and vertically

I am trying to vertically center a text and a button within a container. The text should be positioned in the middle of the div, while the button should be aligned to the right. What is the best way to achieve this layout where the text element is centere ...

CSS animation is supported on most browsers with the exception of Safari

I'm facing an issue with my animation that works fine on all browsers except Safari. I've tried using the autoprefix extension in VSCode to automatically add CSS vendor prefixes, but the animation still isn't functioning correctly. Here&apo ...

Use jQuery to apply a class to some input elements when certain events like keyup or

If I type something in the input field, it should add a border to the li tag containing the text. The current script works fine, but is there a way to make this jQuery script shorter? Thank you for your help! .add_border{ border: 2px solid #000 !impor ...

Issues with Scrollspy in Bootstrap 4: Troubleshooting the problem

I have been following the Scrollspy implementation in Bootstrap 4 documentation, but unfortunately, it is not functioning properly. Can anyone provide guidance on resolving this issue? One thing to note is that my body has a position: relative This is ho ...

Converting an HTML <img> tag into a Base64 encoded image file: Step-by-step guide

Recently, I made changes to the appearance of an image by adding CSS filters using the "style" attribute of an <img> tag. <img src="myImage.png" style="filter: grayscale(100%)"> As a result, the image now has a different look and I am looking ...

Inconsistency in width of Bootstrap 4 card layouts

On my webpage, there are three cards displayed as seen in image 1. However, the cards do not have the same width in columns 1. When viewed on mobile (Chrome), the widths are all different and the bottom two cards are touching, as shown in image 2. How can ...

The resizable function in jQuery is not functioning as expected

Within my project, the initial page includes the following code snippet: html <div id="box"> <div id="header"> <span id="title"></span> <span id="button">X</span> </div> <div id="text"> </div> ...

using boostrap modal leads to background displacement

Just starting out with bootstrap and encountering a modal bug: when I click on a modal button, the background shifts to the right by 15px. My current bootstrap template is version 3.3.0. I attempted to update to the latest 3.3.4 version, but unfortunately ...

What steps can be taken to enhance the responsiveness of this Bootstrap 4 code?

I've been trying to make this code more responsive, but I haven't found a suitable solution yet. When the browser window shrinks to mobile sizes, the list becomes too narrow and the picture/video items on the right end up small and aesthetically ...

Is it possible to make side elements expand to occupy the remaining screen space beyond the container?

This is what it's supposed to look like: The goal here is to have the red element on the left expand to fill the remaining space beside its content, as well as the grey on the right. I am utilizing bootstrap which means the center elements occupy 117 ...

iOS is not recognizing the <a> tag but is instead honoring the :hover property

Within my list, I have a div element wrapped in an anchor tag. Here is an example of the code: <li> <a href="http://google.com/"> <div id="tease-info"> <div class="inset-img-border fade"></div> <img src=" ...

I am eager to run the code that I retrieved from the server. I have access to the code in my console and I desire for it to execute on the main browser page

Currently, I have a simple Google Chrome Extension that includes a button. By using AJAX, I am fetching a script from a server in my browser's console. Essentially, clicking on the extension reveals a button which, when clicked, fetches the script fro ...

Customize YouTube iframe styles in Angular 4+ with TypeScript

Has anyone been successful in overriding the style of an embedded YouTube iframe using Angular 4+ with TypeScript? I've attempted to override a CSS class of the embed iframe, but have not had any luck. Here is the URL to YouTube's stylesheet: ...

Is it possible to incorporate a similar box on a webpage?

I am trying to find a way to add a similar box to a webpage like the one shown in this image. The design I am referring to is from Reddit's theme, but I would like to know how to create a box with a different color and then have another box next to i ...