日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > CSS >内容正文

CSS

CSS属性之attr()

發布時間:2023/12/2 CSS 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CSS属性之attr() 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

attr()準確的說,不應該是一個屬性,而是一個CSS的函數,我們先看看MDN上的介紹吧:

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外,其余都還是試驗性的(簡單說就是不穩定,瀏覽器不一定支持)。

那具體怎么用呢,給大家舉個栗子,前段時間剛好用到的,給按鈕實現提示功能,就是鼠標放上去后,出來個小提示:

<div class="wrap"><a href="#" class="btn" data-tip="點擊作答">一個按鈕</a> </div> .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()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。