Guide on stacking a transformed 3D div on top of a masked layer with higher Z-index without success

I am attempting to stack a green div on top of a blue div using CSS transformations. The blue div acts as a masked layer, while the green div is a dialog that should appear on top.

I have tried adjusting the z-index property, but the blue div always ends up on top of the green one.

If I rearrange the HTML so that the blue div is a sibling of the green div, it works as intended. However, I would like to keep the structure the same with the blue div as a parent sibling to the green div.

Any suggestions?

Here is the link to the jsFiddle for reference: http://jsfiddle.net/YRTxt/9/

CSS code:

#wrapper{
    width:100%;
}
#red, #green{
    height:200px;
    width:400px;
}
#red{
    background-color:red;
    position:absolute;
    -webkit-transform: scale(1);
}
#pink{
    background-color:pink;
    height:250px;
    width:150px;
    top: 50px;
    position:absolute;
    -webkit-transform: translate3d(0%,0px,0px);
    -webkit-perspective: 1000;
}
#green{
    background-color:green;
    position:absolute;
    -webkit-transform: translate3d(0,0,0);
    top:100px;
    right: 0px;
    left: 0px;
    z-index: 1111;
}
#blue{
    background-color: blue;
    width: 100%;
    height: 100%;
    opacity: 0.8;
    position: absolute;
    top:0px;
    right: 0px;
    z-index: 100;
}

HTML code:

<div id="wrapper">
    <div id="red">
        <div id="pink">
            <div id = "green"/>
        </div>
    </div>   
</div>
<div id="blue">
</div>

Answer №1

To ensure z-index works properly, it is essential to assign z-index values to both elements. I made some adjustments to the CSS in this http://jsfiddle.net/rTkyR/ example by applying z-index to the blue and green divs.

Here's the updated HTML structure:

<div id="wrapper">
    <div id="red">
        <div id="pink">
            <div id = "green"/>
        </div>
    </div>   
</div>
<div id="blue">
</div>

And here are the corresponding CSS styles:

#wrapper{
    position:relative;
    width:100%;
}
#red, #green{
    height:200px;
    width:400px;
}
#red{
    background-color:red;
    position:relative;
}
#pink{
    background-color:pink;
    height:250px;
    width:150px;
    top:50px;
    right:20px;
    position:absolute;
}
#green{
    background-color:green;
    position:absolute;
    -webkit-transform: translate3d(0,0,0);
    top:0px;
    right: 0px;
    left: 0px;
    z-index: 1;
}
#blue{
    background-color:blue;
    width:100%;
    height:100%;
    opacity:0.8;
    position:absolute;
    top:0px;
    right:0px;  
    z-index:0;
}

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

Ways to create spacing between vertically stacked columns in Bootstrap

I have created a website using Bootstrap and PHP to display data from 18 categories in columns. The code for listing the categories in a single row is shown below: <div class="row"> <?php foreach($categories as $val){?> <div class="col ...

I am experiencing an issue with the HTML5 video tag as it is not displaying the

Having trouble playing a user-uploaded video using the <video tag. The video doesn't seem to load into the DOM properly. Here's the code snippet: function Videos ({uploadedFiles}){ if (uploadedFiles) { console.log(uploadedFile ...

Issue with JQUERY where HTML select element is not visible

$(document).ready(function(){ var selArr = [ {val: 'corsair', text: 'Corsair'}, {val: 'evga', text: 'EVGA'}, {val: 'antec', text: 'Antec'} ]; $('#pSupply& ...

What is the best way to incorporate progressive JPEG images onto a website?

I am currently working on a website called winni.in that is built using Java, Html, and Javascript. I would like to incorporate progressive image rendering upon page load, but I lack the necessary knowledge. I have come across and explored the following re ...

Arrangement of Divs in Mobile Design - Utilizing Bootstrap 4 Rows and Columns

I've been grappling with a layout issue while using Bootstrap 4, specifically concerning the positioning of elements on mobile devices. I was wondering if anyone could lend me a hand with this challenge. Let me illustrate the desired layout: Link to ...

react native ScrollView items with uniform padding at the top and bottom

I'm currently working on a scroll component that resembles a gallery of images. My goal is to center the images based on the device height with equal padding on both the top and bottom. However, I'm facing an issue where the top padding does not ...

Tailwind CSS - when it comes to styling, larger screen media queries are taking precedence over smaller media queries

Currently tackling screen responsiveness issues in a Nextjs + Tailwind CSS project. All Tailwind breakpoints are functioning correctly except for "sm" and below. Snippet of the problematic code: <div className="bg-red-200 sm:bg-white md:bg-gray-70 ...

having difficulties in separating the mat-table header

It may seem like a basic question, but I'm having trouble figuring it out. I'm not sure if this requires a CSS change or something else. I'm looking to add a divider between my table header similar to the one highlighted in the screenshot be ...

Setting up multiple base tags in AngularJS for different modules

When working with angularjs, there is a "#" that needs to be removed. This can be achieved by setting: $locationProvider.html5Mode(true); Additionally, adding the base tag ensures normal functionality when the page refreshes. If <base href="http://exa ...

Display a loading image during the execution of the Exec_Shell Script

Looking to add a loading image while script.sh is executing Check out the code snippet below: <?php if (isset($_POST['restartserver'])) { shell_exec("my-script.sh"); } ?> <html> <body> &l ...

Choosing the right framework for implementing push notifications can be a critical decision. Should

I am currently working on a Java application that requires the server to send push notifications to the client every one second. To achieve this, I am using HTML5 server-sent events for one-way communication from the server to the client. However, my conce ...

Preserve the div's aspect ratio using CSS styling

Is there a way to design a flexible div element that adjusts its width and height in sync with the window's size changes? Do any CSS techniques exist that would allow the height of the div to adapt based on the width, while still preserving its aspec ...

How to align the last item in the bottom row using Flexbox styling

Is it possible to center the last element when resizing the window to a smaller resolution, even though the parent's justify-content parameter is set to space-between? I understand that using center or space-around would achieve the desired result, bu ...

The legend color in a JavaFX StackedBarChart does not adhere to the chart color CSS styling

Within my application, using JDK version 1.8u51, I need to assign specific colors to different data categories in a StackedBarChart. To accomplish this, I have created the following CSS: .root{ -fx-ok-color: darkgreen; -fx-critical-color: darkblue ...

The color of the textbox does not remain when it is focused

I've developed a custom CSS button style, which you can see here: http://jsfiddle.net/karimkhan/SgTy2/ However, when I implement the same CSS within the <style> tags on my page, the effect is not the same. It looks like this: The actual CSS on ...

What is the best way to maintain scrollbars on mobile devices?

I'm currently building a cross-platform application using Angular 4 that needs to work seamlessly on both mobile and desktop devices. Is there a special trick to prevent the scrollbars from disappearing when viewing this page on a mobile browser? I&ap ...

Is there a way to extract and store an image from a webpage using selenium, beautifulsoup, and Python 3?

Currently, my main goal is to extract and save a single image from a website post logging in. After examining the image, I discovered that it has a full xpath of /html/body/form/main/div/section/div[1]/div/div[2]/div/img. My plan is to utilize beautiful so ...

Exploring the world of using Bootstrap containers, rows, and columns

I have a good grasp on containers and columns, but I am a bit confused about rows. The example below shows a 50/50 split. <div class="container"> <div class="row"> <div class="col-md-6"> 50 / 50 Content </ ...

Conceal the URL and any parameters upon successful completion of AJAX request

In my ajax js code, the solonreport.jsp file returns a URL link that connects to a local report server and generates an Excel report. However, when using this link with the window.open(json.url) function, the link and parameters are visible to the user. ...

Automate the process of filling up and activating a bootstrap dropdown upon a click, and clearing it out when it is

Is there a method to reveal the dropdown content only upon clicking instead of displaying all content at once and increasing the lines of HTML code? Perhaps using an onclick attribute on the button and incorporating a function inside? var data = [{ " ...