Universal CSS selector to match any and all HTML d

2019-02-22 13:43发布

问题:

This question already has an answer here:

  • CSS selector for attribute names based on a wildcard 3 answers

Is it possible to match all nodes that have a data-* attribute using only CSS?

Here are examples of attributes I would like to match:

data-scope
data-sessionlink
data-visibility-tracking

I could do

*[data-scope] *[data-sessionlink] *[data-visibility-tracking]

but I am looking for something more compact. Furthermore, I don't know all possible data-* attributes I might encounter in my application.

回答1:

It is currenly impossible to use wildcard masks to select elements by an attribute-name part.

There is a recent thread in the www-style@w3.org mailing list, where Simon Pieters from Opera has proposed a nice possible syntax that has got some acceptance in the thread, so there is a chance that it will become standard somewhen in the future:

x-admin-* { ... }
[data-my-*] { ... }