Challenges with z-index in Chrome/Safari and Firefox when nesting elements

In the current setup, it seems that .second needs to be positioned above .third, which is only happening in Firefox. Unfortunately, I am facing difficulty as I cannot separate .second from .fifth.

Just to provide some context: .third is intended to act as a modal background to darken the content of .fifth and the footer .fourth. The actual content of the modal is within .second. This Web App is specifically designed for Safari on iPad.

JSFiddle

<div class="first">&l;/div>
<div class="fifth">
    <div class="second">I should be on top.</div>
</div>
<div class="third"></div>
<div class="fourth"></div>

.first{
    z-index: 10;
    /* styling */
    position: fixed; top: 0; left: 0; right: 0; height: 50px; background: lightblue;
}
.second{
    z-index: 9;
    /* styling */
    position: fixed; top: 100px; left: 50px; right: 50px; bottom: 100px; background: darkseagreen;
}
.third{
    z-index: 8;
    /* styling */
    position: fixed; top: 50px; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.1);
}
.fourth{
    z-index: 7;
    /* styling */
    position: fixed; bottom: 0; left: 0; right: 0; height: 50px; background: indianred;
}
.fifth{
    /*styling*/
    position: fixed; top: 50px; left: 0; right: 0; bottom: 50px; background: darkgrey;
}

Answer №1

Make sure that the .fifth element has a higher z-index value compared to the .third element.

    .first{
        z-index: 10;
        /* styling */
        position: fixed; top: 0; left: 0; right: 0; height: 50px; background: lightblue;
    }
    .second{
        z-index: 9; /* You probably do not need this */
        /* styling */
        position: fixed; top: 100px; left: 50px; right: 50px; bottom: 100px; background: darkseagreen;
    }
    .third{
        z-index: 8;
        /* styling */
        position: fixed; top: 50px; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.1);
    }
    .fourth{
        z-index: 7;
        /* styling */
        position: fixed; bottom: 0; left: 0; right: 0; height: 50px; background: indianred;
    }
    .fifth{
        z-index: 9;
        /* styling */
        position: fixed; top: 50px; left: 0; right: 0; bottom: 50px; background: darkgrey;
    }
    <div class="first"></div>
    <div class="fifth">
        <div class="second">This should be displayed on top.</div>
    </div>
    <div class="third"></div>
    <div class="fourth"></div>

Answer №2

Successfully relocated .second from within .fifth. It functions for me, but a completely satisfying solution remains elusive.

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

Personalizing the predefined title bar outline of the input text field

The outline color of the title in the input textbox appears differently in Google Chrome, and the bottom border line looks different as well. <input type="text" title="Please fill out this field."> https://i.stack.imgur.com/iJwPp.png To address th ...

Limiting click event to only Image component in Next.js

Is there a way to trigger a click event only on the image itself, rather than the entire parent div? When setting width and height for the parent div, the click event seems to encompass the entire area. For instance, if the image is 600 pixels wide by 300 ...

Utilize Python to extract information from an HTML table

I am looking to extract data from an HTML table using a Python script and save it as variables that can be later utilized in the same script after loading them in if they exist, into a separate file. Additionally, I would like the script to disregard the f ...

Using CSS min-height: 100vh will ensure that the container has enough height to fill the entire viewport

Utilizing min-height: 100vh; in my inner call to action div placed on top of a background video has been mostly successful. However, I've encountered an issue where using 100vh with the absolutely positioned video seems to introduce an unwanted margin ...

Add a new element to the page with a smooth fade-in animation using jQuery

var content = "<div id='blah'>Hello stuff here</div>" $("#mycontent").append(content).fadeIn(999); Unfortunately, the desired effect is not achieved with this code. I am trying to create a sleek animation when adding new content. ...

My AJAX request seems to be redirecting to my PHP file instead of simply returning the response text. What could be causing this issue?

I am currently working on a project for my Web Engineering course and I am incorporating jQuery to execute an AJAX request to my PHP file using the POST method. The task specifies that "each time the [submit] button is pressed, the form data should be disp ...

When an HTML email is sent from the Outlook 2007 Exchange server, it may appear as plain text when viewed on

After extensive searching, I've come across two old threads with unanswered questions on this topic. In our office, we have a Windows XP PC designated for "production" that sends out emails in HTML format. These emails contain multiple excel Cells for ...

What is a reliable method for automatically refreshing a webpage despite encountering server errors?

I'm working on an HTML+JS web page that refreshes itself automatically every few seconds using http-equiv="refresh". The problem is, sometimes the server returns a 502 "bad gateway" error, preventing the HTML code from loading and causing th ...

Aligning Content in the Middle of a Bootstrap Row

I'm struggling to horizontally center the content in the "row" class div. I've attempted using justify-content-center and other variations. <div class="container"> <div class="row"> <div class="col-md-4 portfolio-item ...

Apply the CSS style to make one element identical to another, while modifying a single property

I am currently working with the following CSS: input[type="text"] { border: 2px solid rgb(173, 204, 204); height: 31px; box-shadow: 0px 0px 27px rgb(204, 204, 204) inset; transition:500ms all ease; padding:3px 3px 3px 3px; } My goal i ...

Utilizing Google Maps to generate outcomes for an online platform

My approach with Google Maps is a bit unconventional. Instead of rendering images, I aim to execute JavaScript code that processes data and returns a text response. However, I soon realized that running JavaScript as a remote web service might not be pos ...

When hovering the mouse over, the text fails to appear

Is there something wrong with my overlay on this image? It darkens when I mouse over, but the text I want to display does not show up. Any ideas? http://jsfiddle.net/cryycw3n/ HTML <div class="square"> <div class="info"> <h2&g ...

How can I make an HTML textbox in C# MVC flash a background color for one second using TextBoxFor?

I'm currently working with MVC and have the following code in my razor view. @Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly", @class=ViewBag.IsLatest ? "latest":""}) I want to briefly change the background color of this te ...

Is it possible to have the soft keyboard automatically appear when the page loads?

On an HTML5 website, I have an input element and I want the soft keyboard to automatically appear and focus on that input element. I attempted to use the 'autofocus' attribute on the 'input' element, but this only focused on the element ...

Unpredictable selection of elements displayed as links

As someone who is relatively new to PHP and HTML, I am working on a website that features a product of the week. However, I have hit a roadblock in implementing my idea. My concept involves creating an array with various products and using array_rand to s ...

Clear out the classes of the other children within the identical parent division

I'm currently in the process of replacing my radio circles with div elements. I've successfully implemented the functionality for selecting options by clicking on the divs, as well as highlighting the selected div. However, I'm facing trou ...

Guide to setting a default value for a select option in Angular 2+

I am having trouble setting a default option in my select box using the html selected property. I want the selected option to be assigned to StartingYear, but currently it's not working as expected. <select [(ngModel)]="StartingYear"> < ...

"Enhance your webpage with Flexslider and captivating stretched images

When working with Flexslider, I encountered a challenge where the image was being stretched to fit the width of the flexslider. I prefer the image to be displayed centered, keeping its original dimensions, and having a black background-color. Is there a ...

Retrieve Image Data by Clicking on Canvas at Precise Coordinates

JS Fiddle Link I'm attempting to implement functionality where a canvas with a linear gradient can be clicked, capturing the image data at that specific point. Additionally, I aim to position a yellow picker relative to the click point on the canvas ...

Creating a 3D slider on Owl-carousel 2: A Step-by-Step Guide

I am trying to create a slider using Owl-carousel, but I'm having trouble implementing it. I came across this example https://codepen.io/Webevasion/pen/EPMGQe https://i.stack.imgur.com/KnnaN.jpg However, the code from this example doesn't seem ...