Description
Thanks for putting together this proposal for anchored positions in CSS! I'm very excited about what this will enable, especially when combined with the popup work. This is a long-time need for the web 😄
I wanted to provide some general, first-impression feedback on the proposal. My main criticism is of the quantity of new syntax/features and the fact that they are "one-off". Let me explain.
The proposal introduces the concept of an anchor()
function in CSS. This references an element's anchor and can be used in calculations. So, if I want to position an element bottom+left of the anchor, I can do this:
top: anchor(bottom);
left: anchor(left);
But why should this be limited to anchors? Why not create a more general function that can reference any element and property? For example:
top: ref(#anchor, bottom);
left: ref(#anchor, left);
This would address the anchored position scenario but open up other scenarios as well. For example, imagine setting the color of an element based on the background of another element, by combining something like ref
with calc
and various color math functions.
Another example is @position-set
. Why not simply have a @set
and open up the possibility of using this approach for other scenarios as well? For example, applying different CSS properties to an element based on other factors, such as how much space that particular element has. I believe there's an element query proposal somewhere. I couldn't find the latest with a quick search. It seems to me that the positioning problem could be solved under the larger feature of element queries. Why not align the approaches?
Every new syntax or feature we add to CSS makes the language harder to learn and understand. So, can we find some solutions for anchored positioning where we get re-use out of the features or syntax? That would really help to reduce the cognitive overhead.
Sidebar:
To help put it in perspective, I just looked up "CSS: The Definitive Guide: Visual Presentation for the Web". It's over 1,000 pages, and it doesn't even cover the updates from the last 4 years. Now, I'm looking over at my bookshelf at my collection of books on C, C++, and Rust...and none of them are close to that long. So, I think we should be very honest with ourselves about how complex CSS has become. In my understanding, much of the design was intended to empower non-coders but I often meet seasoned engineers who have trouble understanding non-trivial CSS. Have we succeeded in the goal? Should we try to course correct?