Is there a way to see the stacking context, in IE/Firefox/Chrome/etc.? - z-index

I'm trying to track down a z-index problem. I'm looking at the page in IE9's DOM Inspector, and I just can't figure it out.
I have one element with a z-index of 10000, and another with a z-index of 7000, and yet the z-index 10000 is drawing below the z-index 7000. Clearly somewhere in the hierarchy, something is setting a stacking context, but I've been browsing up and down the hierarchy and I haven't been able to find it.
Nothing other than these two elements, so far as I can see, has a z-index set. And nothing as a opacity value set. and I'm seeing this in FF5 and IE9, so it's not the old IE<7 stacking context bug.
Do any of the browsers have a tool that will tell me which element is setting a stacking context?
Thanks.

If you use Chrome https://github.com/gwwar/z-context is a simple extension to see:
If the current element creates a stacking context, and why
What its parent stacking context is
The z-index value
and important, like aprohl5 said: The z-index property can affect the stack order only if the position is explicitly set to fixed, absolute, or relative.
This is a nice way to mantain order with Sass https://www.smashingmagazine.com/2014/06/sassy-z-index-management-for-complex-layouts/

For Chrome: the chrome 3d 'layer' tool does most of what you'd want I believe (similar to the other answer which is for MS Edge)
Find it in dev tools > overflow menu / 3 dots (hidden by default) > 'more tools' > 'layers'
https://www.youtube.com/watch?v=6je49J67TQk

The current of MS Edge (using the Chromium engine with a build of "Beta", "Dev", or "Canary") now features: "Debug z-index stacking content with 3D View in the Microsoft Edge DevTools"
"a new feature to help debug z-index stacking context. The general 3D View shows a representation of the DOM (Document Object Model) depth using color and stacking, and the z-Index view helps you isolate the different stacking contexts of your page."
Press F12 (Windows), and then select the "3D tab" in the lower pane (may have to click "...") to view a visual representation.
More information:
https://blogs.windows.com/msedgedev/2020/01/23/debug-z-index-3d-view-edge-devtools/

For Google Chrome and Firefox, I've created an open source extension that not only tells you if the element creates a z-index and why, but also shows a tree-like view of all stacking contexts in the page, and the stacking contexts that they're competing with regarding to the z-index value. You can see all these informations directly in the browser devtools, check out the github page for more info.
CSS stacking context inspector for Chrome
CSS stacking context inspector for Firefox

in newer versions of firefox you have 3D view by pressing Ctrl+Shift+I then clicking the 3D or 3D box icon to access

For z-index to work, you have to explicitly set the position to fixed, absolute, or relative.
Here's a great explanation: http://coding.smashingmagazine.com/2009/09/15/the-z-index-css-property-a-comprehensive-look/

Related

Context menu for Tabulator

I try to use column header menus and row context menus in my tabulator but nothing appear. Then I realize in the DOM that the menu is there but out of the window and at the top of the tree in the dom, it's the div with the class tabulator-menu.
The DOM, the div with smd take the whole page
I use Vuejs with Bootstrap 4.
How to make it appear at the right place ?
Thanks
The menu is appearing in exactly the correctly place in the DOM.
It is standard practice in a lot of context menu libraries to append the menu directly to the body rather than to the element that triggered it, this happens because menus are often long and overflow their containing element, by absolutely positioning the elements in the DOM the sit on top of these and prevent this being an issue.
It is hard to say without seeing an example, but it is likely a z-index issue that is causing the problem.
By default Tabulator menus have a z-index of 10,000 if you have anything with a z-index higher than this it will sit over the menu.
To resolve this you simply need to add a bit of CSS after you have imported the tablator style sheet, that changes the z-index to be higher than any others on your page:
.tabulator-menu{
z-index: 99999999;
}

Nav menu that spans entire container width with constant horizontal padding

I've created a nav menu like in the screenshot below. It spans the entire width of the container and the left/right padding of each menu item is constant. This was easy to do by hardcoding the left/right padding in the CSS, but I want the paddings to be able to change as the site admin edits the menus.
Is there a way to do this with pure CSS (CSS3 is okay)?
This was easy enough to do with jQuery (I totaled up the width of the menu items and calculated the necessary padding). But I ran into some issues on some browsers due to our use of Google Web Fonts. On Chrome and Firefox 4 on Windows (not on Mac), the web font was not loaded at the time that my script ran, resulting in incorrect width measurements. I tried running the script in the jQuery's DOM ready event and in the Google Font API's active event. The active event worked in Chrome but in Firefox 4 it was often fired before the font had been applied.
Thanks in advance.
Here's a jsfiddle of a potential different solution.
Using that layout, and assuming the number of menu items is going to change, you call a recalculation method once a list item is added/removed. In this example provided, I've used YUI3 to do the DOM manipulation, but you could do that a number of ways. Note - I didn't test the javascript function, its "probably working pseudo code".
(You may need to make subtract a further 2% or so from the list item widths, if you're trying to deal with IE6/7)
Use jQuery's .load event as suggested by user thirtydot.

Better dialog shadows in YUI 2?

Here's a tricky one: has anybody seen a YUI dialog/panel implementation with nice OS X style shadows around the dialog, instead of the blocky shadow that is implemented by default with the "underlay" element?
You can see this type of shadow on Amazon.com popup windows. It requires quite a bit of PNGs but looks very nice.
I'm thinking of inserting extra DIVs or replacing the .underlay element, and hook into the dialog size event to adapt the dimensions. The latter would be required because YUI uses some CSS trickery to make the underlay element "snap" to the dialog dimensions with CSS only in modern browsers, and uses a manual dimension update for IE.
EDIT: Just checked YUI 3. The Panel widget is not available yet, only the Container and it's still beta. So I'm looking at solving this in YUI 2.
PS: Oh I guess I could include the PNG shadow as part of the Panel's header, body and footer (hd, bd, ft), as an extra padding. And use a css rule to hide YUI's underlay. Hmmmmmm I just wish I didn't have to do this because it changes calculations for the draggable area, it's not a great way to do it.

Adjusting browser zoom level with Javascript

In the 2-frame 'rows=' frameset I have, if a user change of the zoom level to less than the 125% value that I coded for, they will see "dead space" between the frames.
This question: How to detect page zoom level in all modern browsers? shows how to detect the browser's zoom level.
Is it possible to adjust the browser's zoom level using Javascript so I can keep users from changing the zoom outside of the desired levels?
Or have I simply forgotten a default coding consideration of some kind? (I've seen CSS's 'zoom' style, where presumably default zoom levels can be set.)
I am also seeing document.body.style.zoom, so seems we could do something like:
if (zoomLevelChange)
{document.body.style.zoom= [some calculation]; }
See How to detect page zoom level in all modern browsers?
Can you edit your question to only be about "adjusting", since the other one has detection covered?

YUI modal panel with non-standard background mask value

I am trying to setup a modal YUI panel above a YUI Tabview. For CSS purposes [1] the tabs have a z-index that goes up to about 20 (depending on how many tabs there are).
The problem I am facing is that the mask that YUI draws for the modality of the panel is behind whatever nonzero mask the tabs have, and so the tabs peek through.
So far I have only found YUI API methods to change the mask of the dialog or panel.
Does anyone know how I can do this for the mask? Has anyone had an issue like this before?
I will shortly be posting the code I used.
TIA!
[1] (CSS designer did this, so I can't change the markup)
The solution is
- after show/render of top modal dialog, call hideMask() for underlying modal dialog
- before canceling top modal dialog, call showMask() for underlying modal dialog
Tip: If calling hide/show mask too early and/or too late, mask "flashing" may be experienced visually.
Looks like configuration value zIndex (for the Panel) combined with the stackMask should do it.
Nothing in the docs about whether stackMask should be called before or after rendering, before or after show etc. There is also an event (configzIndex) which fires when the zIndex property is changed.

Resources