The z-index property functions properly in Firefox and IE, however, it experiences issues in Chrome

Having trouble with z-indexes in Chrome. The orange div should be positioned behind the black div, which it does everywhere except in Chrome. Any solutions? Here is the current situation:

.page {
    height:900px;
    background:orange;
    width:80%;
    position:relative;
    z-index:8;
    top:120px;
}

http://jsfiddle.net/yXTF6/4/

Answer №1

It is important to note that the z-index should be set in the background class, not the top-img class.

If the background class itself is not positioned above other elements, adjusting the z-index within its descendants will not have any effect.

To see changes in action, visit this fiddle - http://jsfiddle.net/vals/cTf72/

.top-img {
    height:100px;
    background:black;
    position:relative;
    z-index:9;
}

I simply transferred the z-index value of 9 from .top-img to .background.

In this scenario, top, page, and background are siblings competing for z-index priority. Once one sibling is chosen, all descendants follow suit. Setting a z-index in top-img is ineffective as it has no sibling competition and cannot impact the parent's (background) z-index.

Answer №2

As mentioned by @vals in the previous response, the current markup setup does not allow for the desired functionality. To address this, I made some modifications to demonstrate how it could be achieved.

To make the page function as intended, I removed the <div class="background"> that enclosed the black bar and image. Additionally, I adjusted the classes for both elements to maintain the same visual effect as before.

You can view the updated version on this jsfiddle link.

Below is the revised HTML and CSS code:

<div class='top-img background'></div>
<img class="background" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSJGQ7eqRuhZQqbX1roKW8zBGVHW-VlmQq0uTGCZjDGDHCRljPp" />
<div class='top'>
</div>
<div class='page'>
</div>

And here is the corresponding CSS:

.background {
    position:fixed;
    width:100%;
}
.top-img {
    height:100px;
    background:black;
    z-index:9;
}
img {
    width:100%;
    z-index:7;
    top : 100px;
}
.top {
    position:fixed;
    width:60%;
    height:60px;
    top:60px;
    background:yellow;
    z-index:10;
}
.page {
    height:900px;
    background:orange;
    width:80%;
    position:relative;
    z-index:8;
    top:120px;
}

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

Using Swift Mailer to add a subject to an email by including the 'mailto:' HTML tag

I am currently using Swift_mailer in PHP to send out automated emails. Recently, I have been tasked with enhancing the email messages by including contact information. To enable users to provide feedback, I want to utilize the html 'mailto' funct ...

Utilizing a shared session variable across various PHP scripts

After trying to transfer array elements between different PHP scripts using session variables, I encountered a problem where nothing was being displayed. Below are the contents of my two PHP files. file1.php <?PHP session_start(); $SQL = ...

I'm new to this, but can someone explain why I'm being redirected to the register_db.php page when I click on the register button?

Why when I click the register button, it redirects me to the register_db.php page instead of sending the data to the database and keeping me on the same register.php page? I want the data to be sent to the database without changing the webpage. register.p ...

Updating the background color using typescript

Before transitioning to angular development, I had experience working with vanilla Javascript. I encountered a challenge when trying to modify the css properties of specific elements using Typescript. Unfortunately, the traditional approach used in Javascr ...

Instructions on eliminating the chosen value from the initial dropdown to ensure it does not appear in the second dropdown, with the value retrieved directly from the database. [Laravel]

<div class="form-group mb-3"> <label for="">item 1 </label> <select name="item1" class="js-example-basic-single" style="width: 100%;"> ...

The custom CSS I have created does not take precedence over the Bootstrap CSS

I'm struggling to understand why my custom CSS file isn't able to override the Bootstrap CSS. I know that my new CSS class should have higher priority than Bootstrap's, but for some reason, it's not working as expected. Here's the ...

An advanced password checker that notifies the user of any spaces in their password

I need help fixing my JavaScript code. The program should prompt the user for a password using a dialogue box, and then validate that the input has no spaces. If a space is detected, the program should stop and display an alert saying "Invalid, contains a ...

Is it possible to create a custom dropdown in react with both radio buttons and checkboxes?

I've been searching for a custom third-party library to meet a specific need I have. Here's a snapshot of the dropdown in question. I looked into https://www.npmjs.com/package/multiselect-react-dropdown but it doesn't cover this particular s ...

What is the best way to scale a div proportionally within a bootstrap grid?

Despite spending hours reading numerous online sources, I am still struggling to fully grasp the CSS/HTML box model. Specifically, I am attempting to create sections with a ratio of 3:2, where 3 represents the width and 2 represents the height. https://i.s ...

The form transmits the URL parameter rather than executing an update

I'm having trouble with my code and can't seem to figure out why it's behaving this way. When I try to update a recordset, the page reloads upon hitting the submit button and multiple URL parameters appear in the address bar. There are two ...

Not all records are compatible with PHP Echo when placed within a paragraph

Looking for some assistance with a simple form set up; <div class="formholder"> <form action="column1.php" method="post"> <input type="text" placeholder="URL:" name="url" required=""><br> <input type="t ...

Ways to dynamically update the content of a variable when the input value is modified

Essentially, I have a straightforward code snippet provided below. It is necessary to update the amount and email whenever those are modified by someone. UPDATE: Credit goes to @ellipsis. Your version is close to perfect, except for the data transmission ...

SignalR enables the display of identical dashboard data pulled from queries on various browsers. By utilizing SignalR/hub, MVC, and C#.NET, the data can

Encountering an issue with my signalr/hub while fetching dashboard data. I'm using 2 browsers to access data based on dates. However, when searching for July on browser 1 and then switching to another month on browser 2, the data in browser 1 gets upd ...

How can I create a dimming effect on a webpage while a Details View Control is being displayed?

I have come across websites that use a technique where when a message box pops up, the rest of the webpage dimmed to emphasize the message. Currently, I am working on building a website using Microsoft Web Developer 2010, specifically an ASP.net site. On ...

Unable to place a div below another div

I am in the process of creating a website for my mother, using my limited knowledge. Despite numerous attempts, I have not been able to achieve the desired outcome. Currently, the website looks like this: https://i.stack.imgur.com/ItOcp.jpg However, I e ...

The Bootstrap Carousel is failing to respond as expected

Having some trouble incorporating a carousel on my landing page. I can see the first image, but the carousel isn't sliding to the next one. I copied the template from bootstrap-carousel, but even the data-bs-interval attribute isn't responding. M ...

Slide the first div upward to display the text in the second div when hovering over the first div

I'm facing an issue where a div needs to move upwards when hovering over it. To see an example, take a look at this JSfiddle. The desired outcome is as follows: As illustrated, the right div is the one being hovered. I have attempted to create this ...

Transforming video files into HTML5 ogg/ogv and mpg4 formats

Is there a reliable software out there that can effectively convert video files (such as avi, flv, etc.) to HTML5 supported ogg/ogv and mpeg4 formats? I have tested a few options but unfortunately none of them seem to get the job done correctly. ...

What is one way to prevent a transformed element from being clipped by overflow-auto?

For my friend's personal site, I am using Bootstrap 4 to create a gallery within a modal. I have managed to make the images expand on hover, but I am facing an issue where the images get cut off at the edges of the modal when I set the overflow to aut ...

What are some solutions for resolving the problem with the anchor attribute in Safari?

There is a problem with the anchor tag used in my website. The number 619-618-1660 is being displayed when I view the site on Safari browser or an iPhone, even though it is written as (href="tel:619-618-1660"). See the image at the link below for reference ...