How can you create a layered block using CSS?

I'm looking to create a page design similar to the one shown in the image below:

Image Link

I had an idea for rotating coordinates, but I am facing some issues. When stacking the layers in the Y-axis, the first layer covers the others and I can't figure out how to make all three visible.

body {
    margin: 0;
    background: #b4e0e1;
}

.layer-container {
    width: 400px;
    height: 400px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -100px 0 0 -250px;
    perspective: 500px;
   transform-style: preserve-3d;
}

.layer {
    width: 500px;
    height: 250px;
    position: absolute;
    transition: all 1.5s ease-in-out;
    cursor: pointer;
    z-index: 1;
}


/* dark blue layer */

.dark-blue-layer {
    background: #234688;
}


/* light blue layer */

.light-blue-layer {
    background: #2abfd5;
}

.white-layer {
    background: #fff;
}

.bottom-layer {
    transform: rotateX(0deg) rotateY(-25deg) translateX(0px);
}

.mid-layer {
    transform: rotateX(0deg) rotateY(-25deg) translateX(20px);
}

.top-layer {
    transform: rotateX(0deg) rotateY(-25deg) translateX(40px);
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="styles.css">
  </head>
  <body>
<div class="layer-container stacked-top">
        <div class="layer bottom-layer dark-blue-layer"></div>
        <div class="layer mid-layer light-blue-layer"></div>
        <div class="layer top-layer white-layer"></div>
</div>
  </body>
</html>

Any suggestions on improving this approach or an easier way to achieve the desired effect?

Answer №1

I'm having trouble understanding your transform settings and the desired outcome, but to achieve a similar look as in the green image, you can utilize box-shadow to create the illusion of "background layers":

body {
    margin: 0;
    background: #b4e0e1;
}

.layer-container {
    width: 260px;
    height: 140px;
    background-color: #fff;
    margin: 20px auto;
    box-shadow: 5px 5px 0 0 #234688, 10px 10px 0 0 #2abfd5;
}
<div class="layer-container"></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

CSS: Stretch the text background to match the width of the container

Is there a way to make the background color of a text cell stretch the width of its container div, rather than just the text itself? https://i.sstatic.net/E3zeL.png Here's the HTML code snippet: <div class='col-md-4'> <span class= ...

Using JavaScript to halt the playback of HTML5 video in 'injected' HTML code

Although I know there have been similar issues resolved here before, none of the suggested solutions seem to work for me. Let me start by explaining my problem. I have a landing page located here: On the portfolio section of the landing page, I hav ...

Is iOS Safari preloading entire MP4 videos before playback?

After conducting a test on our homepage using www.webpagetest.org, I found that the autoplay HTML5 9MB fullpage background video loads quickly and plays smoothly on Windows Chrome. However, iOS Safari takes around 23 seconds to load as it waits for the ent ...

PHP is receiving data from $.post in an invalid format

I am facing a challenge in sending a JavaScript Object() to a PHP file in the correct format that $.POST requires. The PHP file does not establish any $_POST[] variables, which suggests that I may be transmitting the data in an improper format. JS: $(&ap ...

Is dividing a container into equal sections possible with flexbox?

Is there a way to create an HTML/CSS structure that divides a fixed-size container into three sections horizontally? The first section should expand based on its content, while the remaining two sections should evenly split the leftover space, with scrollb ...

Failing to hide a div on hover: Hoverintent's shortcomings

When I hover over the div with the unique identifier id="navbar", it doesn't seem to trigger any actions. I have included the following script in my document head: <script type="text/javascript" src="https://ajax.googleapi ...

Center or left-align the divs

Can anyone offer assistance with this section of code? HTML: <div id="holder"> <div class="box"> </div> <div class="box"> </div> <div class="box"> </div> <div class="box"> </div> </div> ...

Stop the background from moving by fixed positioning the content

After reading an enlightening article, I decided to create a supporting example for the questions that have arisen. body{ height:100%; width:100%; margin:0px; } h1{ margin:0; padding:0; } .wrapper{ height:100vh; background: url('htt ...

How can you connect a CSS file from a CSS directory in WordPress?

Completely new to wordpress theme development here! I am attempting to incorporate the style.css file located in the CSS folder within my root directory. Can someone guide me on how to do this? I'm eager to get an answer as soon as possible. ...

Certain HTML elements on the webpage are not functioning properly when attempting to incorporate a div tag

One of the challenges I'm currently facing is that the links for HOME and ABOUT ME in the header section are not accessible when the 'data' div is added. Strangely, the DOWNLOAD and CONTACT ME links still work fine. This issue seems to be oc ...

Lineup of pictures aligning with the consistent left margin of surrounding content

I am looking to create a row of images that aligns with the same margin-left as other content on my webpage, similar to the title in the example image provided. This row of images should scroll horizontally and extend all the way to the edges of the page. ...

The inner panel height does not extend to 100% when there is overflow

When pressing the submit button on a panel containing components, an overlay appears but does not cover the entire parent panel if scrolled to the bottom. Additionally, I want the spinner to always be centered, whether scrolling or not. I've tried usi ...

Is there a way to resolve the issue of the hero image appearing behind the text box without relying on media queries?

I have a hero image with a text box overlapping the hero slightly. However, when I add content below the box, it appears under the text box. While my code includes some media queries that work well, I believe there must be a way to encapsulate the hero and ...

creating a live updating dropdown menu using Node.js and MySQL

Upon a user clicking and selecting a client, I would like to dynamically update the region dropdown menu with options that are related to that specific client from the databaseenter code here This is my client table: Here is the Region table, where clien ...

Modify table cell content based on boolean value - HTML

Currently, I am working with a table that displays properties from an object. Is there a simple method to change the text displayed in a cell instead of the true/false values it is currently set to? For example, one of the columns indicates whether the ob ...

Tips for switching the background image in React while a page is loading?

Is there a way to automatically change the background of a page when it loads, instead of requiring a button click? import img1 from '../images/img1.jpg'; import img2 from '../images/img2.jpg'; import img3 from '../images/img3.jpg& ...

The Visualforce page is not displaying page breaks correctly for cells with rowspan in the table

Having encountered a similar issue to this question: table rowspan page break On my Visualforce page, I have an HTML table with a custom rowspan in one column (varies based on the number of spanned rows) and I'm experiencing a styling problem (see is ...

I want the name to be retained in storage to prevent the item from being mistakenly renamed when deleted based on its index

After pressing the "add layer" button in the box shadow generator, a new layer is added. For example, let's say I have added 3 layers (Layer 1, Layer 2, Layer 3) and then deleted Layer 2. After deletion, the remaining Layers are Layer 1 and Layer 3, b ...

Navigating through Expression Engine and utilizing conditional statements

Would greatly appreciate some assistance with this issue. I am working on an Expression Engine website and encountering difficulties with simple conditionals for navigation active states. Despite having a color state designated within the styles, there s ...

Enhanced Bootstrap Carousel with White Background Transitions

Having trouble articulating my issue, so here's a video that should clarify: https://example.com/video I'm using a bootstrap carousel template for a full-width slider. Despite my efforts to remove the white-space transitions, they persist. Am I ...