-
Notifications
You must be signed in to change notification settings - Fork 715
[css-pseudo-4] ::self-link pseudo, for self-linking #10498
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
Interestingly, this is effectively a |
Very similar, tho the requirement that the target be linkable (and the pseudo itself being a link and triggering hash-navigation semantics, rather than just scrolling a target into view) does separate them a bit. (You need to be able to right-click and copy link, or click and copy the link from the address bar, for example.) I don't know if the concepts are actually close enough to be worth coalescing. |
The CSS Working Group just discussed The full IRC log of that discussion<emilio> flackr: as TabAtkins wrote, it's a very common pattern (bikeshed etc mentioned)<emilio> ... this adds a link to the heading that you can link to <emilio> ... developers write tools to add these <emilio> ... the proposal is to add a pseudo to generate this before the element <emilio> ... long list of proposed behavior <emilio> ... main one is it requires the content is linkable which means it has to have an ID attr <Rossen9> ack fantasai <emilio> fantasai: main issue, sometimes they want it at the start or at the end <emilio> ... the other is sometimes you want a link to the container, not the heading itself <emilio> ... e.g. <section id=foo><h1>... <emilio> ... you could add the id to both but the desired thing is to target the section <emilio> ... so I like the idea <emilio> ... I don't think it's a problem to do it with CSS <emilio> ... but needs a way of solving these two <emilio> flackr: the second seems more tractable <emilio> ... we could allow it to refer to the nearest ancestor with id <emilio> fantasai: that won't get you reasonable behavior for the fifth heading in the section or something <emilio> ... you'd be jumping too high <emilio> ... maybe fine <emilio> ... but if you have somewhat unpredictable markup... <emilio> ... [missed] <emilio> ... it's a bit tricky <emilio> flackr: not sure I understand the use case <emilio> ... isn't the <section> what you link the one you want? <emilio> fantasai: the nearest element with an id might be <main> or what not <emilio> flackr: ah because they forgot or something <emilio> 1+ <emilio> q+ <emilio> flackr: I supposed if there was a functional pseudo you could use `attr(id)` to refer to yourself or something <emilio> fantasai: that might be more practical <Rossen9> ack emilio <emilio> ... I think those are my two concerns <fantasai> scribe+ <fantasai> emilio: Is it well-defined to have generated interactive content? <dandclark> emilio: My question is is it well defined to have generated interactive content? <dandclark> ...What's the click event target? <dandclark> ...Might be fine but might need some work on DOM side as well <emilio> flackr: there is common behavior when you click on pseudos that you dispatch on the outer element, not great but... <emilio> ... it is at least targettable <emilio> ... we could explain this in the future <dandclark> emilio: But I think the targets @@@ is mostly an effect of the generated content. Not quite pointer events but sort of. Must be targetable. Thinking about user-select. <emilio> flackr: not sure I have the answer about how to support before / after <emilio> q+ <Rossen9> ack emilio <dandclark> emilio: What if instead of making new pseudo you make it content function or something? That way you can use ::before and ::after, can target anything <emilio> ... that way you could use content: self-link(self) or self-link(closest) or something <emilio> ... and would solve the before / after issue <emilio> flackr: yeah <emilio> Rossen9: let's take it back to the issue |
What happens if you apply this pseudo on a link tag? Or is it limited to headings specifically? I've seen people do links for individual paragraphs, though it's not as common. See for example articles on https://publicdomainreview.org/ |
Same thing that happens if you insert an
No, any element that's linkable (or, based on the conversation during the meeting, any element at all, as long as some ancestor is linkable). |
Okay, so distilling the TPAC comments (thanks for running the topic, @flackr!):
I like these ideas! So, here's a new proposal to discuss: Add a new This rough idea has been proposed in the past, fwiw, but I can't find the old emails about it because Gmail search is a lot less useful now. |
A very common UI pattern these days is to have headings (and sometimes other elements with an ID) provide a link to themselves, to make it easy to grab a link specifically to that element. Both Bikeshed and ReSpec specs do this for all headings (and for some other elements); GitHub does this for headings in Markdown files; tools like https://github.com/daviddarnes/heading-anchors exist to make it easy to get this effect in HTML; etc.
We should consider adding this as a pseudo-element for convenience to authors, so they don't have to either add some busywork markup, run a preprocessing step, or run JS over their page, just to get useful self-links.
Previously this wasn't really doable; at the moment, pseudo-elements aren't focusable in Chrome, for example. But we're fixing that for Carousel-related purposes, since that proposal also has navigation-related pseudo-elements that need to be part of the page's focus order. I'll assume that this is indeed fixed in UAs, so a pseudo can participate in the focus order and other AT features the same as an actual link element; we could put a requirement in the spec that UAs have this behavior before they implement this pseudo.
Proposed behavior:
content
isn'tnone
. Also requires the originating element to be linkable, per the host language's semantics. (In HTML, this means the element has an ID.)This is potentially better done as an HTML feature, fwiw, tho that would require adding an attribute or whatever to every element you want to apply this to. That's certainly far less work than adding the markup by hand is today, but it's not nothing, and generally you'll want to apply this to all headings/etc in your document, with identical behavior across all of them, so having an HTML attribute isn't great usability-wise.
The text was updated successfully, but these errors were encountered: