通用CSS选择器来匹配任何和所有HTML数据 - *属性 [英] Universal CSS selector to match any and all HTML data-* attributes

查看:376
本文介绍了通用CSS选择器来匹配任何和所有HTML数据 - *属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 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.

最近有一个主题在www-style@w3.org邮件列表中,Simon Pieters从Opera提出了一个很好的可能的语法一些接受的线程,所以有一个机会,它将成为标准的未来:

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-*] { ... }

这篇关于通用CSS选择器来匹配任何和所有HTML数据 - *属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆