CSS 3D transformation disrupts the Z order that Iframe follows

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">
        <div id="center">
            <div class="transform1">
                <div style="display: inline-block; background-color: red; width: 400px; height: 200px; transform: translate3d(-200px, -100px, 0)"></div>
            </div>
            <div class="transform2">
                <div style="display: inline-block; background-color: green; width: 400px; height: 200px; transform: translate3d(-400px, -100px, 0)"></div>
            </div>
            <div class="transform2">
                <iframe style="transform: translate3d(0, -100px, 0)" width="400" height="200" src="https://www.youtube.com/embed/aMDFhjpMTEY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
            </div>
        </div>
    </div>
    <style>
        #root {
            position:relative;
            perspective: 400px;
            height:800px;
            overflow:hidden;
        }
        #center {
            transform-style:preserve-3d;
            transform:translate3d(50%, 50%, 0);
            height:100%;
        }
        #center >* {
            position:absolute;
        }
        .transform1 {
            transform-style:preserve-3d;
            transform:translate3d(0, 0, 200px);
        }
        .transform2 {
            transform-style:preserve-3d;
            transform:translate3d(0, 0, 100px);
        }
    </style>
</body>
</html>

I believe that the div and iframe in transform2 should function similarly. Here is an example of how they should look.

https://i.sstatic.net/5pgYt.png

However, the result I am seeing looks like this:

https://i.sstatic.net/a5ttk.png

The iframe seems to be ignoring the Z order determined by CSS 3D transforms, even between iframes. Why are they ignoring the Z order? How can this be fixed?

Answer №1

It's interesting how positioning the red div at the end seems to resolve the issue:

#root {
  position: relative;
  perspective: 400px;
  height: 800px;
  overflow: hidden;
}

#center {
  transform-style: preserve-3d;
  transform: translate3d(50%, 50%, 0);
  height: 100%;
}

#center>* {
  position: absolute;
}

.transform1 {
  transform-style: preserve-3d;
  transform: translate3d(0, 0, 200px);
}

.transform2 {
  transform-style: preserve-3d;
  transform: translate3d(0, 0, 100px);
}
<div id="root">
  <div id="center">
    <div class="transform2">
      <div style="display: inline-block; background-color: green; width: 400px; height: 200px; transform: translate3d(-400px, -100px, 0)"></div>
    </div>
    <div class="transform2">
      <iframe style="transform: translate3d(0, -100px, 0)" width="400" height="200" src="https://www.youtube.com/embed/aMDFhjpMTEY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
        allowfullscreen></iframe>
    </div>
    <div class="transform1">
      <div style="display: inline-block; background-color: red; width: 400px; height: 200px; transform: translate3d(-200px, -100px, 0)"></div>
    </div>
  </div>
</div>

Answer №2

Interestingly, z-order is not a factor in the code you provided.

The function translate3d is primarily used for mathematical translations, creating a zoom effect with the 'tz' parameter rather than adjusting the z-order between elements as might have been assumed.

Additionally, by adding the red div, the HTML structure was altered, causing the red div to appear on top of the other elements.

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

Initiate a file upload by clicking the trigger button while the video is paused

I'm attempting to pause the video at the 3rd second and trigger a click on the choose file button immediately after. Despite my attempts to create another element to trigger the click on that, it doesn't seem to be working in a chain-like manner. ...

New button attribute incorporated in AJAX response automatically

data-original-text is automatically added in ajax success. Here is my code before: <button type="submit" disabled class="btn btn-primary btn-lg btn-block loader" id="idBtn">Verify</button> $(document).on("sub ...

The fuse-sidebar elements are not being properly highlighted by Introjs

I have recently developed an angular project that utilizes the fuse-sidebar component. Additionally, I am incorporating introjs into the project. While introjs is functioning properly, it does not highlight elements contained within the fuse-sidebar. The ...

An unidentified element is displayed as undefined

I am trying to implement a CSS change for mobile devices, but an unknown variable keeps showing up as undefined. Despite researching various tutorials and finding multiple solutions, I am struggling to grasp them as I am a novice in JavaScript and HTML. T ...

Utilizing /deep/ and the triple greater than symbol (>>>) within Angular 2

After researching the /deep/ and ::shadow selectors, I've come across conflicting information. In a discussion on Stack Overflow: What do /deep/ and ::shadow mean in a CSS selector? It was noted that Chrome has deprecated the /deep/ combinator and i ...

What is the reason behind both paragraphs being displayed in a shade of blue in this snippet of code

.red p { color: red; } .blue p { color: blue; } <div class="blue"> <p> first </p> <div class="red"> <p> second </p> </div> </div> Initially, I expected the first paragraph to be bl ...

What is the most effective way to divide a page in dompdf?

I am currently working on a project using Laravel and the dompdf library. I have encountered an issue with page breaks when the content exceeds a certain character limit. The problem can be seen in this image: https://i.sstatic.net/ALtLu.png I am looking t ...

How can I add an image to a canvas using a button?

Having trouble with my studies and looking to create a custom shirt website. Posted below is the beginner code I have: If anyone knows how to upload an image onto a shirt canvas using a button, as well as change the shirt color with another button, please ...

Having trouble with GSAP Scrolltrigger PIN functionality in Next.js?

When I comment out the pin: true property in my code snippet below, everything works as expected except that the container wrapping the sections that should scroll horizontally does not stick to the top. However, if I uncomment the pin: true line, the enti ...

Revert button design to default after second click

Looking for some assistance here. I have a button that toggles between displaying and hiding information. When the information is displayed, it should have one style, and when it's hidden, it should have another. Currently, I'm able to change the ...

Creating a smooth image transition effect using CSS

I have successfully implemented a code that allows for crossfading between images when the mouse hovers over them. Now, I am looking to modify the behavior so that the crossfade effect happens only once when the mouse passes over the image. In other words ...

What is the best method for storing a variety of HTML form data in a database?

I am currently working on developing a survey system that includes the feature of creating various types of questions through a drag & drop HTML form builder. The idea is for a client to create their survey form, which will then be stored in a database tab ...

Module not found in Node.js environment (webpack)

I seem to be encountering an issue with loading any modules. Despite reinstalling my operating system, I continue to face the same error when attempting to use any module. I have tried reinstalling node, clearing the cache, and more. To view the code, pl ...

SimpleLightBox refuses to function

Having trouble getting SimpleLightBox to work properly? It seems like when you click on an image, it opens as a regular image on a blank page. I've added the JS and CSS files correctly (I double-checked in the source code) and included the HTML and JS ...

Experimenting with incorporating easing effects into jQuery tabs

Could someone please help me implement an easing/fading effect on tabs using jQuery? I am looking to add an easing effect to my current code and also incorporate two CSS classes to change the background color along with the text color. Thank you for any as ...

animate the alignment of right-aligned text to move to the right side and realign to the left

I need help with a small menu-list that should expand when the mouse is nearby. By default, the menu is aligned to the right, but on hover, every other item shifts to the left to accommodate the increased height (check out the JSFiddle). ul { font-siz ...

Encountering numerous errors when attempting to incorporate lottie-web into my JavaScript file

I am in the process of creating a unique audio player for my website utilizing HTML, CSS, and JavaScript. I encountered some challenges while trying to get it to work effectively on Codepen as well as my text editor. The animations were not functioning pro ...

PHP image retrieval is not functioning correctly and the image is not appearing as it

I'm facing some challenges when it comes to displaying images with PHP. I attempted to use this solution from Stack Overflow, but unfortunately, the image is still not appearing correctly. Within my PHP file that deals with the HTML layout, the code ...

Having trouble creating a full-screen modal with NgbModal by passing content as a component?

I've been using Bootstrap widgets and trying to create a full-screen modal where the header sticks on top, the footer stays at the bottom, and the body scrolls in the middle. Initially, I found a simple HTML solution for this: However, when I want to ...

The toggle checkbox feature in AngularJS seems to be malfunctioning as it is constantly stuck in the "off"

I am trying to display the on and off status based on a scope variable. However, it always shows as off, even when it should be on or checked. In the console window, it shows as checked, but on the toggle button it displays as off Here is the HTML code: ...