首页 / CSS / CSS属性之attr()
CSS属性之attr()
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CSS属性之attr(),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1796字,纯文字阅读大概需要3分钟。
内容图文
![CSS属性之attr()](/upload/InfoBanner/zyjiaocheng/415/55778aaa64c546eb943511c970f58da4.jpg)
Summary
The attr() CSS function is used to retrieve the value of an attribute of the selected element and use it in the style sheet. It can be used on pseudo-elements too and, in this case, the value of the attribute on the pseudo-element's originated element is returned.
The attr() function can be used with any CSS property, but support for properties other than content is experimental.
简单翻译下,英语水平有限,主要是给英语比我还差的朋友作参考,高手可以无视:
CSS函数attr()是用来获取被选中元素的属性值,并且在样式文件中使用。它也可以用在伪类元素里,在伪类元素里使用,它得到的是伪元素的原始元素的值。
attr()函数可以和任何CSS属性一起使用,但是除了content外,其余都还是试验性的(简单说就是不稳定,浏览器不一定支持)。
那具体怎么用呢,给大家举个栗子,前段时间刚好用到的,给按钮实现提示功能,就是鼠标放上去后,出来个小提示:
<p class="wrap"> <a href="#" class="btn" data-tip="点击作答">一个按钮</a></p>
.btn { display: inline-block; padding: 5px 20px; border-radius: 4px; background-color: #6495ed; color: #fff; font-size: 14px; text-decoration: none; text-align: center; position: relative; }.btn::before { content: attr(data-tip); width: 80px; padding: 5px 10px; border-radius: 4px; background-color: #000; color: #ccc; position: absolute; top: -30px; left: 50%; transform: translate(-50%); text-align: center; opacity: 0; transition: all .3s; }.btn::after { content: ''; border: 8px solid transparent; border-top: 8px solid #000; position: absolute; top: -3px; left: 50%; transform: translate(-50%); opacity: 0; transition: all .3s; }.btn:hover::before { top: -40px; opacity: 1; }.btn:hover::after { top: -13px; opacity: 1; }
当然attr()还可以获取更多的其他属性,比如a标签里的href属性等,更多的用法大家自行尝试吧。
更多CSS属性之attr() 相关文章请关注PHP中文网!
内容总结
以上是互联网集市为您收集整理的CSS属性之attr()全部内容,希望文章能够帮你解决CSS属性之attr()所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。