-
Notifications
You must be signed in to change notification settings - Fork 658
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
[selectors-4] Attribute match syntax extended to cover tag selectors #6571
Comments
I'm a bit concerned about this defeating many optimizations that engines have for tag selectors. If you have a tag selector you are guaranteed that it'll never impact performance of elements without that tag, but these selectors you'd need to match against all elements. |
@emilio I was thinking something the same, which made me think that the [tag^="x-"] syntax might be best, to give some indication the selector had similar performance characteristics to attribute substring matches. |
@astearns I'm partial to that approach myself. It feels clearer and easier for authors to learn/understand. The |
Note that attribute selectors with Note that |
+1 🎉 Questions:
|
@Westbrook There's a good point here that you could easily accidentally target tags you didn't mean to simply from a lack of knowing every tag and which are being used on a page. Regex proposal would cover an |
Another possibility:
|
I wouldn't pollute :tag(= x-foo) /* like `x-foo` but different specificity */
:tag(^= x-)
:tag($= -foo)
:tag(*= -foo-)
:tag(= div s) /* case sensitive: matches <div> but not <DIV> */ |
Agree that a pseudo-class is probably the best way to go to allow for the complexity we need without making existing stuff messy. I suspect we want to override the specificity so it still counts as a tag selector for specificity purposes, tho. Same with attribute names, but keep the normal specificity. |
I like the new pseudo-selector idea, but I wonder if instead of :custom /* selects all non-native elements */
:custom(= x-foo) /* like `x-foo` but different specificity */
:custom(^= x-)
:custom($= -foo)
:custom(*= -foo-)
:custom(= div s) /* case sensitive: matches <div> but not <DIV> */ The reason for For example, |
@andy-blum This would be quite cool, especially considering the combination of |
Link: https://www.w3.org/TR/2018/WD-selectors-4-20181121/
With the advent of custom elements and the growing popularity of web component libraries (especially those with common prefixes), the need for a way to target a tag selector using attribute match syntax has increased.
Use case
I have library x with a set of components:
x-foo
,x-bar
,x-bat
. I want to write styles influence only those components on the page but I'm not sure which components are in use.Suggestions
In this thread, a few ideas were proposed: https://twitter.com/castastrophee/status/1433418836364210182?s=20
I'll do my best to summarize:
x-* { color: red; }
.:is()
pseudo-selector i.e.:is(x-*)
[tag^="x-"]
The text was updated successfully, but these errors were encountered: