帝王谷资源网 Design By www.wdxyy.com

为什么实现这种效果呢,其实这效果也是根据title的提示说明衍生出来的,只是因为原生的比较丑陋,像这种衍生出的插件后很多种,如jquery-ui的tooltip,Bootstrap的tooltips等等,有很多种插件库。

有时候我们不需要那么大的插件库,其实就一两个地方需要做一些提示(tooltip),所以可以使用CSS的content属性与 :before 及 :after 伪元素配合使用来实现插入生成内容。

查看效果如下

使用CSS content的attr实现鼠标悬浮提示(tooltip)效果

html代码如下

<a class="dui-tips" data-tooltip="我是一个3cbest.com提示">w3cbest.com</a>

“data-“为自定义属性,如上自定义提示data-tooltip=”我是一个3cbest.com提示”,配合before、after使用content的attr调用自定义提示,content: attr(data-tooltip);

content: attr很好理解,只要会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%);
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
CSS,content,attr,鼠标悬浮

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?