The z-index property is affected by CSS transform

I have encountered multiple questions on this issue, but none of the suggested solutions seem to work for me. I have a grid of boxes with CSS transforms applied to each. Upon page load, jQuery appends an invisible pop-up <div> to each box. When hovering over a box, the pop-up is supposed to show up, but it ends up appearing underneath the boxes despite having a higher z-index. I've tried following suggestions from similar queries like this one and that one, but no luck so far.

You can view the JSFiddle here

HTML:

<a id="aaa" class="box effect-4"></a>
<a id="bbb" class="box effect-4"></a>

CSS:

.box {
    width:335px;
    height:203px;
    float:left;
    margin:0 15px 15px 0;
    position:relative;
    -webkit-transform: translate3d(0px, 0px, 0px);
    z-index:0;
}
.popup {
    width:325px;
    height:340px;
    background:#333;
    z-index:99; 
    position:absolute;
    display:none;
    -webkit-transform: translate3d(0px, 0px, 0px);
}
.effect-parent {
    -webkit-transform: perspective(1300px);
    -moz-transform: perspective(1300px);
    transform: perspective(1300px);
}
.effect-4 {
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    transform-style: preserve-3d;
    -webkit-transform-origin: 0% 0%;
    -moz-transform-origin: 0% 0%;
    transform-origin: 0% 0%;
    -webkit-transform: rotateX(-80deg);
    -moz-transform: rotateX(-80deg);
    transform: rotateX(-80deg);
    -webkit-animation: flip ease-in-out forwards;
    -moz-animation: flip ease-in-out forwards;
    animation: flip ease-in-out forwards;
}

jQuery:

jQuery(document).ready(function() {
    $('.box').each(function() {
        $(this).append(popupMarkup);
    });
    $(document).on({
        mouseenter: function(){
        var popup= 'popup'+$(this).attr('id');
        $('#'+popup).fadeIn();
    },
    mouseleave: function() {
        var popup= 'popup'+$(this).attr('id');
        $('#'+popup).fadeOut();
    }
    }, '.box');
});

Answer №1

The reason why your popup is not displaying correctly is due to its placement within another div that already has a default z-index set. This issue has nothing to do with the transformation of the elements.

In the words of Jonathan Sampson:

A child element cannot have a higher z-index than its parent element.

It's as simple as that.

There are several possible solutions available, so you can choose the one that best fits your requirements:

  • Move your popup outside of its parent div to ensure that its z-index is independent of the parent's.
  • Assign a different z-index value to the red box (higher than the other red box) - check out 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

Tips for successfully passing PHP variables to a JavaScript function

Having trouble passing the selected values of two comboboxes to another PHP file using AJAX. How can I pass both values in one function? <script> function showUser(str,str2) { if (str == "" || str2 =="") { document.getElementById("tx ...

Open <i> leading to increasing <i> within every <p>

Lately, I've been delving into the depths of the HTML5 specification and stumbled upon a fascinating snippet in the section on syntax errors within the document. https://i.sstatic.net/PfWFb.png I've learned that it's crucial for the openin ...

verifying the AJAX validation request URL

I am seeking a way to ensure that the valuable data generated by my ajax code on my webpage can only be accessed when the request originates from my site. This will prevent third parties from using the data without permission. I intend to implement this ...

Securing PHP Code with HTML Encoding

I'm having trouble parsing an HTML page due to encoding issues. Despite trying popular solutions like using utf8_encode() and utf8_decode(), my results remain unchanged. Below is a snippet of my code along with the output. Code $str_html = $this-> ...

Expanding Nested Resources with Rails and JQUERY Toggling

I'm currently facing a challenge with toggling a "finish" action involving nested resources in rails. I've been struggling to make it work as intended and keep receiving the 'Couldn't find List without an ID' error. While I underst ...

Scrolling Bootstrap tabs

Here is the code snippet provided below: JavaScript: var hidWidth; var scrollBarWidths = 40; var widthOfList = function(){ var itemsWidth = 0; $('.list li').each(function(){ var itemWidth = $(this).outerWidth(); itemsWi ...

When resizing the browser window, this single horizontal page website does not re-center

I am in the process of creating my very first one-page horizontal website using jQuery and the scrollTo plugin. This site consists of 3 screens and initially starts in the center (displaying the middle screen). To achieve this, I decided to set the width o ...

What are some strategies to prevent a fixed sidebar from obscuring content while zooming in?

I've been working on adding a fixed sidebar for a table of contents (TOC) to a website, where the sidebar stays in place as the user scrolls up and down. My implementation includes the following HTML code: https://i.sstatic.net/jAY8l.png and CSS co ...

What is the reason that modifying a textarea causes the AJAX loading of content to be interrupted?

I am currently developing a feature that allows users to quote comments on my website. When a user wants to reply to a specific comment, they can simply click on the "quote" button next to that comment. This action triggers a script that adds the quoted co ...

What can I do to prevent Bootstrap sections from overlapping on smaller screens?

While my website looks great on my laptop screen, I'm facing an issue when viewing it on a smaller device. The text from the first section is overflowing into the lower section, which disrupts the layout. Despite being new to bootstrap, I've trie ...

Ways to enable file/result downloads on a website using HTML

Could you please take a look at this repository: https://github.com/imsikka/ArtGallery I am looking to create a downloadable result using a download button. I can create the button, but I am unsure of how to make the file actually downloadable. Do I need ...

Identify a specific HTML template using jQuery

I am currently working on implementing datepickers in various HTML templates. The issue I am facing is that the functionality only seems to work in my index.html file. When I try to replicate the same setup in another template, it does not function proper ...

A web address shared in a post appears within the nested frame of an iframe

I'm encountering a somewhat confusing issue. I am attempting to submit a URL to an iframe located on the same page. Upon clicking submit, the iframe replicates the current page, but with the correct URL displayed in the duplicated iframe. It's ma ...

JQuery: Issues with attaching .on handlers to dynamically added elements

I'm currently developing a comment system. Upon loading the page, users will see a box to create a new comment, along with existing comments that have reply buttons. Clicking on a reply button will duplicate and add the comment text box like this: $( ...

Using Angular $resource to store an object with arrays

Consider a scenario where we have a User $resource structured as follows: $scope.user = { name: 'John', hobbies: [1, 2, 3] } If we were to save User.save($scope.user) to the server, it would send the following parameters: name: 'John& ...

Automatically clear text input field after choosing a new radio button using jQuery

I am dynamically adding Radio button function RadioButton() { $.ajax({ type: "POST", url: "VPATransaction.aspx/SetRadioButton", data: "{}", contentType: "application/json; charset=utf- ...

Ensure that the buttons are arranged in a single row and have horizontal overflow in the mobile version

After using Bootstrap, I managed to create a row with multiple buttons. I encountered an issue where the buttons do not align properly when viewed on mobile devices, as depicted in the image provided. Is there a solution to ensure that these buttons alwa ...

create an HTML element using JavaScript to display a box with dimensions of n

I am attempting to create a grid in an HTML document using only plain JavaScript. The idea is to take a number from a URL and use that as the basis for generating the grid. For example, if my URL looks like this: abc.html?num=5, then I would need to creat ...

The colors of a jVector Map change based on the display of two datasets

I have two sets of data, 'ctrl.gdpData' and 'ctrl.pdpData', which I am currently displaying on the jVector world map as shown below: $('#world-map-gdp').vectorMap({ map: 'world_mill', series: { ...

What is the best way to use jQuery to update the color of an SVG shape?

Hello everyone! I'm excited to be a part of this community and looking forward to contributing in the future. But first, I could really use some assistance with what seems like a simple task! My focus has always been on web design, particularly HTML ...