scroll-to-css-selector icon indicating copy to clipboard operation
scroll-to-css-selector copied to clipboard

The :target pseudo-class

Open mathiasbynens opened this issue 6 years ago • 6 comments

In CSS, the :target pseudo-class can be used to style the currently-targeted element, i.e. the element with an id matching the URL fragment.

Do we want to extend :target to support these targetElements?

mathiasbynens avatar May 22 '18 12:05 mathiasbynens

If there are multiple matches, I assume the first is used (like querySelector), so :target should only target the first match.

jakearchibald avatar May 22 '18 12:05 jakearchibald

Here's a JSBin (though with out using any JS 😉) that shows the use of :target and shows that what @jakearchibald highlights is correct (it's essentially the same as querySelector; i.e. first match "wins"): https://jsbin.com/rekalan/edit?html,output

BigBlueHat avatar May 22 '18 16:05 BigBlueHat

If there are multiple matches, I assume the first is used (like querySelector)

Your assumption is correct — this is mentioned in the README here. :target so far has only ever applied to a single element at a time, so this wouldn’t change.

mathiasbynens avatar May 22 '18 17:05 mathiasbynens

@BigBlueHat I think Jake was talking about this proposal matching only one element at a time when he voiced his assumption. For :target this is already the way it works indeed.

mathiasbynens avatar May 22 '18 17:05 mathiasbynens

So...

.content :target { display: block }
#targetElement=ul>li

Would actually match:

.content ul > li:firt-child

This is another reason direct mapping to #querySelector and/or #querySelectorAll would help clarify things.

BigBlueHat avatar May 24 '18 15:05 BigBlueHat

Here https://github.com/bokand/ScrollToTextFragment/issues/1 I propose :target-within for Scroll-To-Text.

laukstein avatar Feb 14 '19 18:02 laukstein