欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用CSS content的attr實(shí)現(xiàn)鼠標(biāo)懸浮提示(tooltip)效果

  發(fā)布時(shí)間:2018-10-10 15:16:03   作者:Tom   我要評(píng)論
這篇文章主要介紹了使用CSS content的attr實(shí)現(xiàn)鼠標(biāo)懸浮提示(tooltip)效果,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

為什么實(shí)現(xiàn)這種效果呢,其實(shí)這效果也是根據(jù)title的提示說明衍生出來的,只是因?yàn)樵谋容^丑陋,像這種衍生出的插件后很多種,如jquery-ui的tooltip,Bootstrap的tooltips等等,有很多種插件庫。

有時(shí)候我們不需要那么大的插件庫,其實(shí)就一兩個(gè)地方需要做一些提示(tooltip),所以可以使用CSS的content屬性與 :before 及 :after 偽元素配合使用來實(shí)現(xiàn)插入生成內(nèi)容。

查看效果如下

html代碼如下

<a class="dui-tips" data-tooltip="我是一個(gè)3cbest.com提示">w3cbest.com</a>

“data-“為自定義屬性,如上自定義提示data-tooltip=”我是一個(gè)3cbest.com提示”,配合before、after使用content的attr調(diào)用自定義提示,content: attr(data-tooltip);

content: attr很好理解,只要會(huì)jq的.attr()就知道什么意思了,本例的content: attr就是獲取data-tooltip里面的值

CSS代碼

.dui-tips {
position: relative;
display: inline-block;
cursor: pointer;
}
 
.dui-tips[data-tooltip]:after,
.dui-tips[data-tooltip]:before {
visibility: hidden;
position: absolute;
top: 50%;
left: 100%;
transition: all .3s;
}
 
.dui-tips[data-tooltip]:after {
 
content: attr(data-tooltip);
transform: translate(-5px, -50%);
white-space: pre;
padding: 5px 10px;
background-color: rgba(0, 0, 0, 0);
color: rgba(255, 255, 255, 0);
}
 
.dui-tips[data-tooltip]:before {
content: '';
height: 0;
width: 0;
transform: translate(-10px, -50%);
border-width: 5px 5px 5px 0;
border-style: solid;
border-color: transparent rgba(0, 0, 0, 0) transparent transparent;
}
.dui-tips:hover:after,.dui-tips:hover:before {
transition: all .3s;
visibility: visible;
 
}
.dui-tips:hover:after {
color: rgba(255, 255, 255, 1);
background-color: rgba(0, 0, 0, 0.8);
transform: translate(5px, -50%);
}
 
.dui-tips:hover:before {
border-color: transparent rgba(0, 0, 0, 0.8) transparent transparent;
transform: translate(0px, -50%);
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論