What is causing z-index to malfunction?

I'm currently working on a web application and facing an issue with a rollover effect that is not functioning correctly. When the mouse hovers over an element, it should be displayed on top, but instead, it appears underneath. I have provided a jsfiddle link for better understanding: http://jsfiddle.net/XmKwt/1/

Even though the z-index property is set appropriately, the right div is still appearing below the left div.

Interestingly, when I remove the "position:relative;" CSS from the code (as shown in the source), the rollover effect works as expected. However, removing this CSS property affects other functionalities in my application, which are not evident in this simplified example.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <style>
    /* Removing this line resolves the issue */

    #featureleft {position:relative;}

    /* End */

    #layoutdiv { text-align: left; width: 940px; }
    #featureleft { width: 580px; float: left;z-index:10; background:red; }
    #featureright { float: right; z-index:100;}
    #copypaste { background-color: #bbb; margin-bottom: 40px; padding-right: 10px; padding-left: 10px; width: 300px; height:200px; margin-left: 20px; border: solid 5px #000; }
    </style>

    <script language='javascript'>
    $(document).ready(function() {
        $('#copypaste').mouseenter(function(){
            p=$(this).position();
            // increase/move by p.left
            move=Math.round(p.left)-0;
            width=parseInt($(this).css('width'))+parseInt(move);
            margin=0-(parseInt(move)-20);
            inputs=parseInt(move)+280;
            $(this).css('width',width+'px').css('margin-left',margin+'px').css('height',$(this).height);
        });

        $('#copypaste').mouseleave(function(){
            $(this).css('width','300px');
            $(this).css('margin-left','20px');
        });
    });
</script>
</head>

<body>
    <div id="layoutdiv" class='container fakewindowcontain'>
        <div id='featurewrapper'>
            <div id='featureleft'>
                <p>Lorem ipsum dolor sit amet, ut eget et enim, nec auctor habitasse eu mattis eget odio, lacinia vivamus libero dictum, tempor nunc nec nam fringilla mauris, et class dolor curabitur ipsum. Commodo ultricies id</p>
            </div>

            <div id='featureright'>
                <div id='copypaste'>
                <p>Lorem ipsum dolor sit amet, ut eget et enim, nec auctor habitasse eu mattis eget odio, lacinia vivamus libero dictum, tempor nunc nec nam fringilla mauris, et class dolor curabitur ipsum. Commodo ultricies id</p>
                </div>      
            </div> 
        </div>
    </div>
</body>
</html>

Answer №1

The #featureright division lacks a specified position (making it equivalent to position: static). As mentioned in my previous comment

"the CSS z-index property is not recognized on elements with a position of static (which is the default)"

Therefore, in order for it to adhere to the z-index property, you must include position: relative in #featureright

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

Class-driven dynamic CSS

Recently, I came across a JSP code snippet that looks like this: <table id="mytable" cellspacing="0"> <tr data-depth="0" class="collapse level0"> <td></td> <td></td> <td></td> </tr> ////... /...// < ...

How can I specify the file path for an image or any other file in a .js or CSS file within DotnetNuke?

Currently, I am delving into DotnetNuke 7 and am in the process of developing a Module using ASP.Net. After successfully creating the Module in Visual Studio 2015, I uploaded it as an Extension in DotnetNuke at www.dnndev.me. All aspects of the Module are ...

Retrieving the Value of a Text Box in jQuery After a Character is Typed

Is there a foolproof method to retrieve the value in a text box after a character has been typed using jQuery? I consistently find myself coming up short on the final character. ...

leaving code block using Express and Node

My code is displayed below: // Implement the following operations on routes ending with "users" router.route('/users') .post(function(req, res, next) { var user = new User(); user.username = req.body.username; user.p ...

Transfer information in the form of a JSON file using discord.js

I am attempting to send a JavaScript object (as JSON data in a JSON file) with a command using discord.js. However, it is proving to be more complicated than sending an image. I have tried using AttachmentBuilder (with or without JSON.stringify), both with ...

Creating unique jQuery objects by comparing specific object properties

I am looking to create an array of unique objects by removing duplicate objects with specific property values. For example, consider the following code snippet where event1 and event2 have identical titles and start values, while event3 and event4 share th ...

Slowly zooming background image

I've been searching all over the place but can't seem to find a clear answer on how to slowly zoom in the background image using CSS. Any help would be greatly appreciated. Currently, my code only zooms the text elements and not the background. ...

Concatenation in JavaScript replaces only the first character of a string

Objective My current task involves extracting SQL statements from a log file and performing simple string concatenation to add a semicolon (;) at the end: var query = line[i] + ";" Issue Expected output: insert into [...]; Actual output: ;nsert into ...

What is the most efficient method for transferring rows from an SQL Database to JavaScript?

Recently, I've been exploring the dynamic features of HTML5 IndexedDB controlled by Javascript and how to sync it with an SQL Server database for offline access. The challenge I'm facing is determining the most efficient method to transfer data ...

In IE8, the section cannot extend to full width

Having some trouble with a section in the footer of a website I'm developing - it won't go full width in IE8. I've tried all sorts of solutions but nothing seems to work. Can anyone else take a look and see if there's something I'v ...

"Encountering a problem with ThreeJs graphics rendering

I recently developed an application using ThreeJs, but I encountered a strange issue. After rendering the 3D graphics, the window appears blank. However, when I click on full screen or adjust the window size, the output becomes visible. Check out Screen s ...

How do I specify filter selectors for events passed as an object in JQuery's on() method?

I've been pondering about the second syntax of JQuery's on() method where events are passed as an object: services.on({ 'mouseenter': function(e){ console.log('enter', e.target); }, 'mouseleave': function ...

What is the reason behind not being able to utilize addEventListener on a variable that has been selected through DOM's getElementsByClassName method?

btn = document.getElementsByClassName('btn'); value = document.getElementById('value'); let counter = 0; btn[2].addEventListener('click', function() { if (btn[2].classList.contains('decrease')) counter -= 1; if ...

Looking to incorporate WAV file playback in Electron with Vue.js or Javascript but facing limitations due to lack of WAV support in Chrome

Chrome doesn't support WAV files, and since Electron is built on Chrome, we are facing a problem. Our recording server software, Asterisk, records calls in the WAV format. With over 100000 recordings, switching to another format is not feasible. Our ...

Record audio without relying on Mediarecorder

I am combining two AudioBuffers to form a single one. I believe this can be done without using the MediaRecorder, as real-time recording is not required. This is my current approach: concatenateAudio(buffers: AudioBuffer[]): void { const totalLength ...

sending information back to the controller with get method (ajax, javascript)

I'm currently facing a challenge where I have an event listener waiting for a button to be pressed. Once the button is pressed, the controller method 'update' is called which then triggers the view method 'input' to fetch data from ...

Django DRF functions properly, however it returns an error when sending a response to an AJAX request

Successfully implemented an AJAX request using PUT in DRF. All functionalities are functioning correctly except for the error callback being triggered: DRF section: class ProductDataViewSet(viewsets.ViewSet): authentication_classes = [SessionAuthentic ...

Utilize a random file import with the help of React JS, Babel, and ES6

Having trouble displaying a random image using webpack. I have a directory with various images, such as: 1.jpg, 1-cropped.jpg 2.jpg, 2-cropped.jpg I want to fetch a random image from this directory without manually adding a reference for each file. I&apo ...

The variable maintains the same value both inside and outside of the loop

I have a list of objects that provide information to a variable, which creates "markers": var markers = [ //testPOW { mesh: ["campDome","POW"], color: iconRed, location: {lat: 43.30985465943113, lng: 11.898409657895801}, visible: true, id: "TestPO ...

How can I retrieve the value of an HTML component when submitting a form?

In my ExpressJS application, I have two pages: home and user. In the home.js file, I create a form that navigates to the user.js page when submitted. While I am able to retrieve values from input components, I am facing issues with other components. How ca ...