什么是CSS attr函数的正确用法是什么? [英] What is the correct usage of CSS attr function?

查看:97
本文介绍了什么是CSS attr函数的正确用法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为这个函数是在IE8中实现的,所以我想知道我能做什么,但是我遇到了麻烦,使它不能工作在除before::after css伪元素之外的任何地方。

  span [color] {color:attr(color); } 

我在Google Chrome中也尝试过,但它没有工作。此外,更动态的事情,如:

  input [value = attr(default)] {color: }在CSS 2.1(这是应该使用的)中,


解决方案这些天), attr 功能在它可以做。唯一可以显示的地址位于 content 属性中, a href =http://www.w3.org/TR/CSS2/selector.html#before-and-after =nofollow noreferrer>:before和:after伪元素。



在CSS 3中,此改变了一点,因为attr()可能返回除了字符串以外的其他类型,它也可以用于其他属性。



但请记住,大多数CSS 3 仍然是一个工作草案,只有很少的功能(不包括值和单位)是候选建议。由用户代理支持CSS 3功能当前在有限和不存在之间不同。大多数浏览器供应商似乎通过实现酷的东西,如圆形边框,文本阴影等,这不意味着很多工作支持它无聊无聊。但是你在这里看到的是绝对超出的,WD的状态在不久的将来不会改变。所以不要指望它在任何地方实施。


Since this function is implemented in IE8, I wanted to see exactly what I could do with it, but I'm having trouble getting it to work anywhere other than the :before and :after css pseudo-elements. Should the following be allowed?

span[color] { color: attr(color); }

I tried it in Google Chrome too, but it didn't work. Also, what about more dynamic things like:

input[value=attr(default)] { color: gray; }

解决方案

In CSS 2.1 (which is what should be used these days) the attr function is a little limited in what it can do. The only place where it can appear is in a content property on :before and :after pseudo-elements. So its sole purpose is generated content.

In CSS 3 this changed a bit, in that attr() may return other types than only strings and it can be used for other properties as well.

But bear in mind that most of CSS 3 is still a Working Draft with very few features (not including Values and Units) being a Candidate Recommendation. Support by User Agents for CSS 3 features varies currently between limited and next to non-existent. Mostly browser vendors seem to fight boredom by implementing "cool stuff" like rounded borders, text shadow, etc. which doesn't mean much work supporting it. But what you were looking at here is definitely beyond that and the WD status won't change in the near future. So don't expect it to be implemented anywhere.

这篇关于什么是CSS attr函数的正确用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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