Home > Web Front-end > CSS Tutorial > Can CSS Selectors Target Elements with Any \'data\' Attribute?

Can CSS Selectors Target Elements with Any \'data\' Attribute?

Susan Sarandon
Release: 2024-11-23 09:23:20
Original
895 people have browsed it

Can CSS Selectors Target Elements with Any

Wildcard Selectors for Attribute Names

Question:

Is there a way to use CSS selectors to target elements that have any "data" attribute, regardless of its specific name?

Answer:

Currently, there is no built-in wildcard selector in CSS that targets attribute names. However, there is a single way to select elements with a specific attribute name:

E[foo]
Copy after login

This selector selects elements with the "foo" attribute, regardless of its value.

Extended Discussion:

While wildcard selection for attribute values is supported through various operators, such as *= and ^=, there is no equivalent for wildcarding attribute names. Proposals have been made for such a syntax, including:

x-admin-* { ... }
[data-my-*] { ... }
Copy after login

However, these are not yet standardized and are subject to browser support.

Additional Notes:

  • The W3C Selectors Level 3 Specification does not include wildcarding for attribute names.
  • Attempts to create wildcard selectors for attribute names, such as [data-*] or [data-^], will not work.

The above is the detailed content of Can CSS Selectors Target Elements with Any \'data\' Attribute?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template