-
Notifications
You must be signed in to change notification settings - Fork 711
[css-anchor-position-1] Allow anchoring to a particular grid area of the target element #8898
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
Comments
It'd be good to have some use-cases for specifying a grid area vs. an element. Ian |
The latest use-case that I can remember — the sidenotes layout. Something like one of my experiments. Here is a quick CodePen: https://codepen.io/kizu/pen/abRebRJ?editors=1100 In it, I have a grid, with some number of columns, and elements going vertically in one of them. Then, I want to be able to position things absolutely with anchors, where:
Here is a video of how this behaves: Screen.Recording.2023-06-01.at.21.28.18.movAnother similar case could be used potentially for something like tables (with the condition that they're implemented using CSS grids instead of table layout; I'll put aside the potential accessibility issues that can bring, let's imagine all browsers would solve this eventually). Then, something like my other experiment would be possible: anchor-positioning-1-3.mp4In the video we can see that we could select different rows/column and areas of a table — if the table was implemented with a grid, and we had an ability to target an area with anchor positioning, this would be trivial. But right now in my experiment I have to explicitly add If I'll remember other cases related to this, I'll add them. |
Another, very use-case idea — placing decorative elements onto the grid gaps or over whole columns/rows when the elements inside of them have different sizes. CodePen: https://codepen.io/kizu/pen/abRezzL Video: Screen.Recording.2023-06-01.at.22.19.15.movIn the example I had to add an When the sizes of elements inside could be different, it can be very hard to select the proper ones. And what if the grid is not static and wraps? Having an ability to use grid areas as targets for our anchors could be really nice in this case, as we would be able to first choose a row, column or an area, and then choose its side — allowing placing things both inside the cells, and outside, on the gaps. |
On the other hand, if we solve the "decorative grid items pseudo-element" problem, we can lean on that instead of trying to solve this within anchor(). I think I'd prefer that. |
Is there any draft for the specs for it/an idea of how it could look? If this (or those) pseudo-elements could have |
Not yet, but I've got a proposal simmering that I'll post later this month that addresses it. |
For decorating gaps, there was this proposal: https://matspalmgren.github.io/css-gap-decorations/Overview.html And for decorative grid item pseudo-elements, #499 |
Yeah my proposal will solve #499 in a slightly different way. |
Read #7661 issue and noticed @tabatkins saying
My issue here would be — I don't think an anchored element, currently, has an access to the grid of an element it would be positioned into? In order to utilize the grid with anchor positioning, right now we would need to have actual elements in the grid that we could then use as the target.
But what if we could target specific grid areas?
There are other cases where we could want to “specify” in more details what exactly we're targeting when selecting an anchor, for example, I agree that we would want an ability to target a particular fragment (#8895).
What if we could introduce a new function like
grid-area()
that could be used for this?This way, for a particular anchor, we would first find the element that is associated with it, then would check if it is a grid, and if so, would try to find the area by the same syntax
grid-area
uses.Alternative considered for a second: using the
grid-area
property itself when the anchor is active, but this won't really work as we could want to have multiple anchors with different grids.The text was updated successfully, but these errors were encountered: