I have an element I would like to keep on top of all page content so I have set the z-index
greater than 0
. This element has a ::before
pseudo-element that also needs to be above the page content. However, this pseudo-element needs to remain behind the main element.
I have seen numerous posts with a solution of setting the pseudo element's z-index
to a negative value but this would then require me to set all other page content to a lower negative number.
I have attempted the following...
/*all other content*/ {
z-index: 0;
}
.element {
z-index: 2;
}
.element::before {
z-index: 1;
}
...but the main element's z-index
doesn't seem to be overwritten by a pseudo-element.
Here is a visual example. I would like the triangle behind the menu but above all other content.
The desired outcome is something like the following but with the other content being behind the triangle (notice cell border is visible in triangle)
How can I accomplish the desired effect?