问题描述
是否可以使用仅 CSS匹配具有数据 - *
属性的所有节点?
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
我可以做
*[data-scope] *[data-sessionlink] *[data-visibility-tracking]
但我正在寻找更紧凑的东西。此外,我不知道在应用程序中可能遇到的所有可能的 data - *
属性。
but I am looking for something more compact. Furthermore, I don't know all possible data-*
attributes I might encounter in my application.
推荐答案
使用通配符掩码通过属性名称部分选择元素是根本不可能的。
It is currenly impossible to use wildcard masks to select elements by an attribute-name part.
最近有一个在[email protected]邮件列表中,Simon Pieters从Opera提出了一个很好的可能的一些接受的线程,所以有一个机会,它将成为标准的未来:
There is a recent thread in the [email protected] 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-*] { ... }
这篇关于通用CSS选择器来匹配任何和所有HTML数据 - *属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!