Open yisibl opened 2 days ago
Thinking further, is it possible to allow <length-percentage>
? To do this, introduce the same scroll-x/y
as background-position-x/y
.
/* Scroll to 200px from the top to display the Back to Top button */
@container scroll-state(scroll-y >= 200px) {
.back-to-top {
display: block;
}
}
This has functional overlap with Scroll-driven Animations
, but I think it would be easier to use and more ergonomic.
@yisibl At that point, I think you'll want to know the position of an element, not just an arbitrary length.
The
overflowing
(will be renamed toscrollable
) feature in the current specification is confusing, and @fantasai expressed similar concerns in #11182.This proposal attempts to explore solutions to more common scenarios.
CSS authors often prefer to get a sense of where the container has scrolled to, and then adapt behavior and style.
Proposal
scroll-to
top | right | bottom | left | block-start | inline-start | block-end | inline-end
Common use cases
back to top
button after scrolling to the bottom of the page.Details
The current
overflowing feature
performs this once every time the page is loaded, which is undesirable in the above use case.Demo
This is the syntax used in the demo video:
Compare this to the following syntax, which implements the same functionality, but with better readability.
https://github.com/user-attachments/assets/f917d6b2-1e6f-42e7-9cbf-91b14f29bc9d