quantummagic a day ago

Unless there is a polyfill for Firefox, it will be at least a couple of years before you can rely on this for public sites.

azangru a day ago

I need a tooltip, with a pointer; but it seems that the current state of the spec does not allow for pointers; and most explainers studiously avoid this use case, as if this isn't a lion's share of what people do with anchored floating boxes.

  • codingdave 20 hours ago

    Tooltips are normally visible on hover, so the pointer is your cursor. I've never added an additional arrow pointing to the element, nor had any designers ask me to do so. So I'd disagree that such a design is the "lion's share", but am curious what types of apps you create where you do find it to be so?

  • johtso 20 hours ago

    Think a common approach is to just display a triangular svg beneath the tooltip:

    https://react-spectrum.adobe.com/react-aria/Tooltip.html#exa...

    • azangru 19 hours ago

      > Think a common approach is to just display a triangular svg beneath the tooltip

      One killer feature of CSS anchor positioning is that it allows you to declaratively define fallback positions if the floating element does not fit into the preferred position. For example, you prefer your tooltips to appear below the anchor; but if the anchor happens to be at the bottom of the screen, there is no space below it, and so the floating element can flip to the top.

      After the flip, the triangular svg will be pointing in the wrong direction.

  • DaiPlusPlus a day ago

    I'm unsure what you mean by "pointer" - normally that just refers to the user's mouse cursor on-screen...

    ...do you mean you want a rich-HTML tooltip that is auto-positioned to ensure it's fully visible w.r.t. the browser's viewport but you also want the tooltip (or UI in general) to include an arrow shape that stays fixed on-target even if might be occluded by the browser?

amelius a day ago

At this point I'm just counting on LLMs to remember all the CSS specification cruft for me.

  • ileonichwiesz 21 hours ago

    In my experience LLMs are surprisingly bad at CSS beyond a very basic level. They work fine if you need to change the color of a button, but when it comes to actual styling work, even intermediate stuff like position:absolute or CSS grid, Copilot or even CC default to outputting correct-looking gibberish really quickly.

    • pahbloo 17 hours ago

      That's telling about CSS design. Folks here on HN are talking about how they purposely ask LLMs about APIs that don't exist, and they hallucinate with a better and more intuitive design that they would come up with on their own.

      I don't know the best solution for the problem, but CSS is a very convoluted one.

eviks a day ago

Would be cooler if the whole system were more flexible: you simply define 2 anchor points (one on the target, another on the source, so center bottom would be bottom width 50% and top width 50%) instead of being limited to the 9 predefined areas

xswhiskey a day ago

It being available on WebKit makes me hopeful for general adoption then.

  • MBCook a day ago

    I’m surprised it’s not in Firefox. I don’t remember the last time I ran into something in Safari and Chrome but not FF.

    I was reading the article and thinking it would be a great thing to adopt for some code we recently wrote, but we have to support Firefox. And since we already have an existing solution that works, no point cleaning it up with this until Firefox adopts it.

    Still, looks like a very nice feature.

Antrikshy a day ago

`position-area` syntax feels a little tough to remember, but I'm glad top/right/bottom/left is still available.

rtkwe a day ago

I was expecting boat anchors haha.

efilife a day ago

Do we really need this? Why won't position: absolute and setting top/left/bottom/right suffice?

  • adamschwartz a day ago

    It solves many of the pain points Tether[0] tried to solve.

    For example it helps when the anchoring element is inside of an oveflow hidden/scroll container, but geometrically you need the tethered element to sit/extend outside of the container (so—for now at least—its DOM node needs to be outside of the container).

    [0] https://tetherjs.dev

  • netghost a day ago

    Yes. Unless you want to rely on JavaScript libraries like popper and FloatingUI, we definitely need this for many use cases.

    The simplest example is if you have content that it not contained by the box you're positioning against. Think tooltips, popovers, etc.

    For some usecases like annotating content, this hugely simplifies things.

  • cyral a day ago

    This always results in a ton of hacky JS to detect how the element should reposition itself if it overflows the screen (depending on the content and screen size)

  • pupppet a day ago

    This relies on being able to set the position relative to a parent selector, this doesn't work if the element you are positioning is not a descendant of the element you wish to anchor to.

  • Antrikshy a day ago

    That's fine for a lot of stuff. It becomes tricky to do certain other things. CSS-only tooltips are notoriously limited in scope.

  • bee_rider a day ago

    Fundamentally no, html was fine. But hey it’s one fewer reason to reach for JavaScript, right?

danielvaughn a day ago

Anchor positioning sounds cool, but I ran into some very unintuitive behavior when I tried to use it. Can’t remember the details, it was a couple years ago.

  • jaffathecake a day ago

    I guess you're being downvoted as a general nay-sayer, but you're right. I tried this feature last month and a bunch of browser bugs and design issues got in the way. I reported them, and they're being worked on https://github.com/w3c/csswg-drafts/issues/12466

    The `margin:0` issue was particularly frustrating & imo should have been covered in the article, as it's a real gotcha when trying to use popover & anchor positioning in combination.

    • danielvaughn 21 hours ago

      Yeah I could have mentioned the actual issues I had.

      My first attempt was to anchor an element to another one that occurred later in the document order, and it didn’t work. The anchor must be placed before any of its dependents. It kind of makes sense, but doesn’t jump out as intuitive.

  • bombcar a day ago

    My problem is always been on sites that have a menu or something similar at the top. The anchor always inevitably goes to the very top of the screen gets covered by whatever menu it is.

    • chiefalchemist a day ago

      Isnt there something like scroll-padding or scroll-margin? More or less an offset you can set so that doesn’t happen