Skip to content
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

[css-position-3] New container-fixed value for position within a @container #8762

Open
brandonmcconnell opened this issue Apr 24, 2023 · 6 comments

Comments

@brandonmcconnell
Copy link

With the growing support for @container, it’d be cool if CSS added a new position value to make an element fixed within the context of its container.

The main workaround for this I've used thus far is to position an element absolute within its parent with the top value offset by the current scroll distance of its parent.

We can certainly bikeshed on the value name a bit more as container-fixed is a bit verbose, but that's the general idea.

@SYwaves
Copy link

SYwaves commented May 4, 2023

I'm having difficulty envisioning how this would work. It feels like this would be the same as establishing the container as a containing block for fixed positioning, but for a descendant item specifically. In practice, it would be the same as absolute positioning.

@brandonmcconnell
Copy link
Author

@SYwaves The same as absolute positioning if the container had a sibling element to the absolute element in its first level that was a scrollable box. Otherwise, an absolute position won't appear "fixed" as the user scrolls in the container.

That approach also necessitates that the absolute element appears on the container's top level (under its relative position, as other elements may also use relative positioning) vs. being any arbitrary number of layers deep as fixed positioning usually supports.

@SYwaves
Copy link

SYwaves commented Jan 10, 2024

Oh, it's something to the effect of background-attachment: scroll, where the fixed thing is attached relative to the border of the container itself?

@bramus
Copy link
Contributor

bramus commented Mar 28, 2024

Also see #7475, specifically #7475 (comment) where I suggested an extension to position: fixed that indicate where something is fixed against.

Fitting things into my proposed syntax, your proposal would become position: fixed / container;

@brandonmcconnell brandonmcconnell changed the title New container-fixed value for position within a @container [css-position-3] New container-fixed value for position within a @container Mar 30, 2024
@xiaochengh
Copy link
Contributor

Looks like another use case of the position-container proposal (#9868)

@brandonmcconnell
Copy link
Author

@xiaochengh Yes, perhaps an extension

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

5 participants