Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bringing a HTML element to front with z-index on overflow in CSS

Tags:

html

css

z-index

I am trying to get the blue rectangle container to have a larger z-index than the other boxes when hovering over elements that overflow the container.

Game 3 here has the larger z-index, but I want to access the Loser select in the blue circle below, however I can't, unless I hover back over the blue rectangle to gain focus.

Is there a way around this where it can be handled with just CSS or do I need JQuery?

I created a Fiddle that can replicate this so ignore any JS errors as the actual page requires quite a bit of includes, however the issue is in tact. Hover over the 4th game which has three dropdowns, Source, Pools, Seeds. You can select Seeds just fine. However, hover over another game at the top then come back down to "Seeds", you can't select it unless you hover over "Pools" again. I need "Seeds" to always be selectable regardless of what the overflow is.

https://jsfiddle.net/cblaze22/qp4L15tj/8/

enter image description here

Current Code For Game Hover (Blue Rectangle area)

The .forward puts a large zindex on the blue rectangle area.

$(element).hover(
                function () {
                    if (!$(this).parent().hasClass('editing')) {
                        $(this).addClass('forward');
                    }
                },
                function() {
                    $(this).removeClass('forward');
                }
            );
like image 680
Mike Flynn Avatar asked Oct 26 '18 14:10

Mike Flynn


People also ask

How do you bring something to the front in HTML?

In order an element to appear in front of another you have to give higher z-index to the front element, and lower z-index to the back element, also you should indicate position: absolute/fixed... Save this answer.

How do I move the Z axis element in CSS?

translateZ() The translateZ() CSS function repositions an element along the z-axis in 3D space, i.e., closer to or farther away from the viewer. Its result is a <transform-function> data type.

How do I make an element on top in CSS?

Using CSS position property: The position: absolute; property is used to position any element at the absolute position and this property can be used to stack elements on top of each other. Using this, any element can be positioned anywhere regardless of the position of other elements.

How do I fix Z index in CSS?

To sum up, most issues with z-index can be solved by following these two guidelines: Check that the elements have their position set and z-index numbers in the correct order. Make sure that you don't have parent elements limiting the z-index level of their children.

What is Z Index 9999 in CSS?

In CSS code bases, you'll often see z-index values of 999, 9999 or 99999. This is a perhaps lazy way to ensure that the element is always on top. It can lead to problems down the road when multiple elements need to be on top. Most of the time you'll find that a z-index of 1 or 2 will suffice for your needs.


1 Answers

This was actually a surprisingly easy fix once you understood the structure and the actual problem. Div's covering div's. First you disable all click events on everything within .bracket-part as they aren't needed. Then you add the click events back onto the selects. To make it more generic for easier use again you can simple change select in the CSS selector a class .re-enable-events or something. The JS about z-index's wasnt actually needed.

#bracket-wrapper .bracket-part select {
  pointer-events: all !important;
}
#bracket-wrapper .bracket-part {
  pointer-events: none;
}

See: https://jsfiddle.net/uws8pf1y/

Pointer events has a very good compatibility rate so this solution should be fine across pretty much all devices.

like image 64
Deckerz Avatar answered Sep 21 '22 18:09

Deckerz