Skip to content

[css-position] property to reverse stack/layer ordering (request/proposal) #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonjohnjohnson opened this issue Mar 8, 2018 · 3 comments

Comments

@jonjohnjohnson
Copy link

jonjohnjohnson commented Mar 8, 2018

https://drafts.csswg.org/css-position-3/#layered-presentation

Not sure how eager browsers would be to develop the feature, but I'm sure most of us have come upon the cumbersome task of needing to shuffle around and/or overspecify z-index values to create effects like...

Example - Notice as you scroll all subsequent pages are revealed from below the current page.

To accomplish a simple reversal of layers in that example, you either have to specify the reverse sequence to the nth z-index or use a flex container that sets flex-direction: column-reverse while reversing the semantic sequence of your content (order-accessibility).

.item:nth-child(1) {z-index: 999;}
.item:nth-child(2) {z-index: 998;}
.item:nth-child(3) {z-index: 997;}
.item:nth-child(4) {z-index: 996;}
.item:nth-child(5) {z-index: 995;}
.item:nth-child(6) {z-index: 994;}
.item:nth-child(7) {z-index: 993;}
.item:nth-child(8) {z-index: 992;}
.item:nth-child(9) {z-index: 991;}
...
.item:nth-child(999) {z-index: 1;}

And I know with the successful implementation of order within [css-flexbox] ('order-modified document order is used in place of raw document order') the implementation might actually be simple. And even if this predicament isn't the biggest in the CSS world, it's still more cumbersome than seemingly needs to be?

Proposing a non inherited property that sets a reverse sequenced local stacking context?

layer-ordering: forward | reverse

With forward being the initial value and guessing reverse would lead to a child element with z-index: 1 sitting above a sibling set to z-index: 2 as well as all other 'normal' layering visualizing in reverse.

Further Reading -> MDN Stacking without z-index

@fantasai fantasai added the css-position-3 Current Work label Mar 8, 2018
@jonjohnjohnson
Copy link
Author

@LeaVerou comment about z-index reversing #1026 (comment)

@tabatkins tabatkins added unknown/future spec and removed css-position-3 Current Work labels Apr 29, 2020
@tabatkins
Copy link
Member

Punting to the eventual Stacking Context spec, now that we've removed that section from Positioning.

@kizu
Copy link
Member

kizu commented Jun 29, 2023

I was recently exploring the possibilities of scroll-driven animations, and controlling the stack/layer ordering was one of the things I experimented on — and it seems that with the scroll-driven animations we could have a work-around/polyfill for this.

Here is the section talking about this case inside my article: https://kizu.dev/position-driven-styles/#controlling-the-stacking

TLDR; we can assign the z-index for elements in a container based on their position inside of it.

This won't solve all the cases for layering, as it requires elements to be in the same context and have at least initial position over one of the axes in a certain order, so it would be still nice to see some way to control this natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants