The effectiveness of z-index and :hover can vary, yielding inconsistent results at times

Feeling a sense of fear about the outcome, I am in the process of creating a small website that includes animations, CSS 3D transforms, and some jQuery elements.

The code is too lengthy to include here, so I have created this jsfiddle for reference.

The structure itself is quite simple, as shown below (with vendor-prefixes omitted for clarity):

<section>
  <article>
    <h1>2012</h1>
  </article>
  <article>
    <h1>2013</h1>
  </article>
</section>
.article {
  position: absolute;
  width: 370px;
  height: 250px;
  margin-bottom: 120px;
  background-size: cover;
  background-position: center;
  border-radius: 10px;
  background: grey;
  z-index: 50;
  box-shadow: -5px 0 3px -4px rgba(0, 0, 0, 0.6);
  -webkit-box-reflect: below -10px -webkit-linear-gradient(bottom, rgba(255, 255, 255, 0.2) 0%, transparent 40%, transparent 100%);
  transition: margin-top 0.3s, width 0.3s, height 0.3s, -webkit-transform 0.3s, top 0.3s, left 0.3s;
  transform: perspective(900px) rotateY(25deg) translateZ(-90px);
}

section article:hover {
  margin-top: -30px;
  width: 430px;
  height: 310px;
  cursor: pointer;
  box-shadow: 0 0 50px 20px rgba(0, 0, 0, 0.2);
  transition: all 0.8s;
  transform: perspective(100px) rotateY(0deg) translateZ(0);
}

The issue I'm facing is that the :hover effect sometimes works and other times it does not. It appears that at times another element is positioned over the article, even though there are no additional elements. Even adding z-index or using the class .activo after clicking an article doesn't solve the issue. The problem persists regardless. Sometimes it works fine, while other times it does not...

Please try accessing the sample link and reload it multiple times. This issue occurs across Safari, Chrome, and Firefox browsers, although Firefox seems to handle it slightly better.

I've noticed that the hover function operates correctly if, during page loading, I quickly move my mouse to the article elements. However, if I wait until the page fully loads before hovering, the effect fails to trigger.

Additionally, I've implemented a bit of jQuery to shift sibling articles when one is hovered. Since the articles are absolutely positioned and expand to cover the entire body upon clicking, JavaScript is necessary to reposition them accurately.

$('article').hover(function (event) {
    $(this).nextAll('article').each(function () {
        izquierda = izquierda_original[$(this).attr('id')].izquierda + 360;
        $(this).css('left', izquierda + 'px');
    });
}, function (event) {
    $(this).nextAll('article').each(function () {
        izquierda = izquierda_original[$(this).attr('id')].izquierda;
        $(this).css('left', izquierda + 'px');
    });
});

The object izquierda_original[] stores the original left values for each element.

Thank you in advance for any assistance provided.

EDIT: After further investigation, I've discovered that the issue lies with the body element. When the height of the body exceeds that of the articles, the hover effect ceases to function properly. This behavior is particularly peculiar, as it's almost as if the body element takes precedence over its child elements.

Answer №1

Your elements are being overlaid by the body tag for some unknown reason.

After encountering the same issue, I found a solution that worked for me.

Start by assigning a z-index to the body tag:

body{
z-index: 1;
position: relative;
}

Next, apply a higher z-index to the section:

section{  
z-index: 2;
position: relative;
}

By following these steps, you can maintain your background and ensure full functionality of the element.

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 managing the width of tr:nth-child(odd)

I am in search of a way to style my datasheets using tr:nth-child(odd). Below is the code snippet I am currently using: My main concern lies in adjusting the width. I aim for it to occupy a space that measures 200px by 400px The depth does not pose an is ...

What is the best way to ensure that an image functions as a clickable hyperlink upon hovering over it?

I am facing a challenge in making an image function as a link. Unfortunately, I have identified the problem, but finding a solution is proving to be quite elusive. When the cursor hovers over the image, it undergoes a slight darkening effect and some word ...

Struggling with configuring a personalized version of Bootstrap 4 in Sass

I am currently in the process of creating a custom version of Bootstrap 4. One of the main changes I want to make is switching the default color ("primary") from Bootstrap Blue to something different. Initially, I made the edits directly to the Bootstrap ...

Having trouble getting any results from a JSON response using the jQuery Tokeninput plugin in PHP?

I am currently trying to implement the JQuery Tokeninput feature on my website. However, when I enter text into the search field, nothing appears and it just continues searching indefinitely... After reviewing the documentation, I noticed that the expecte ...

Issue with JQuery UI autocomplete functionality when using JQuery version 1.5.1

After updating to the most recent version of JQuery, I realized that my getJson calls were no longer functioning. Therefore, I have been slowly transitioning them to '$.ajax' requests and including "dataType: 'text json'". However, I r ...

If there is a space within a variable, the div will not collapse

Here is the jsfiddle link I wanted to share: http://jsfiddle.net/nvx4tkLt/8/ I have observed an issue with collapsible divs when a variable contains spaces. For instance, in the provided jsfiddle example, clicking on "Brothers Home" does not collapse th ...

What is the best way to access dropdown sub-menu options from a complex multi-level navigation bar

Struggling to figure out how to open my dropdown sub-menu using CSS. Hoping to make it so the user can open it by hovering over the corresponding tag. I attempted to use #lablinksDD to trigger the opening of #ddSbMenu when hovered over #menuDD with #labLin ...

Tips for adding a space before the footer in a document

Implementing a Top Navigation Bar with grey spacing Avoid having any extra space just before the footer: Organizing my Layout File ("navigation_top" refers to the black navigation bar at the top) %body = render "navigation_top" .main-content .cont ...

Ensuring Proper Tabulator Width Adjustment Across All Browser Zoom Levels

<div id="wormGearTabulatorTable" style="max-height: 100%; max-width: 100%; position: relative;" class="tabulator" role="grid" tabulator-layout="fitDataTable"><div class="tabulator-header" role="rowgroup"><div class="tabulator-header-co ...

rails/jquery/ajax: The completion function is not being triggered

My code was functioning correctly without any errors when making an AJAX call that didn't require a return value. In my Javascript (specifically coffeescript), I had the following: $.ajax({ url: "/images/" + image_id + "/" + action, type ...

Is there a way to generate a hierarchical list menu using strings?

Within an HTML Application (HTA), I am utilizing vbscript to retrieve a list of subnet locations which is output as text in the following format: Chicago Denver Dallas Dallas/North Dallas/South Dallas/West Dallas/West/Building1 Dallas/West/Bu ...

Improving content updates by avoiding excessive use of .click and .html

I am currently exploring jQuery as part of a side project to enhance my skills and experiment with different functionalities. I would like to seek advice from the community on how to improve the approach I have taken so far. You can view my sample to under ...

When reloading jQuery datatable with AJAX, the form submission is triggered once more

Utilizing jquery datatables to retrieve data from the server, I am also able to edit this table to input new data. However, upon adding auto-refresh functionality after an addition, the create request is being submitted repeatedly. var dataTableInitilizat ...

Creating a dynamic scene with three.js within an HTML div element

I've been searching for solutions but can't seem to figure it out for this particular scenario. https://codepen.io/rkimo/pen/vdwxJj Essentially, I just want to include this blob in a div so that I can add content before and after it and be able ...

Bars of varying heights (Google Chart)

I have incorporated a Google chart within a mat-grid-tile. In this setup, one column displays a value of 50, while the other showcases a value of 30. These particular values are sourced from myService and are accurate. Although when I hover over the bars i ...

What is the best way to implement CSS properties on Material UI components?

I've recently started exploring Material UI, but I'm having trouble understanding how the spacing properties function. I'm trying to utilize the "spacing" feature for various elements, but it appears that it only works for "Box" components a ...

Updating class after refresh of ng-repeat in AngularJS/Javascript

I am currently using angularJs in conjunction with cordova. Within my ng-repeat loop, each item has an ng-click event that stores the value of the item in an array. Additionally, when I click on an item, it toggles a class on the corresponding div (using ...

What is the process for translating a single line of code from jQuery to vanilla JavaScript?

How should the code block $('#output').on('input ','.dynamic-Qty', function(e){ be handled? $('#output').on('input ','.dynamic-Qty', function(e){ let z = e.target.dataset; console.log(z.id) conso ...

Retrieve information from a text

I retrieved this data as a string from a webpage using jQuery and need help parsing it. When I attempted to use jQuery.parseJSON, I encountered the error Uncaught SyntaxError: Unexpected token n. The specific values I am looking for are "surl" and "imgur ...

The Highchart formatter function is being called twice on each occasion

My high chart has a formatter function that seems to be running twice. formatter: function() { console.log("starting formatter execution"); return this.value; } Check out the Fiddle for more details! ...