Home >Web Front-end >CSS Tutorial >Why Isn't My CSS `attr()` Function Working?
attr() Not Working in Browsers: Unraveling the Mystery
CSS3's attr() function, designed to retrieve values from HTML attributes and use them as CSS properties, has been puzzling developers due to reported issues in popular browsers. Let's delve into the reason behind this unexpected behavior.
The W3C specifications for attr() define a syntax that includes separating the attribute name and unit with a comma. However, contrary to this documentation, it has been discovered that this comma must be removed for the function to work correctly.
Even after adjusting the syntax, attr() remains inoperable in major browsers because the Level 3 version of the function, which introduces this feature, is not implemented in any browser.
To the disappointment of developers, the implementation of this Level 3 version remains uncertain, as it is currently at-risk in the latest editor's draft of the spec. This means that the attr() function we are familiar with is the Level 2.1 version, which is fully supported across major browsers and operates differently.
Although there is some progress in potential browser support, it is still under consideration. If this feature aligns with your development needs, please consider suggesting its implementation through the appropriate feedback channels.
The above is the detailed content of Why Isn't My CSS `attr()` Function Working?. For more information, please follow other related articles on the PHP Chinese website!