!不需要JS就可以定制化hover效果
核心:
1. :hover:after
2. css的attr()函数
举个例子,亲测有效:
html:
<div title="提示内容">声乐</div>
css:
div {
position: relative;
}
div:hover:after {
position: absolute;
margin-left: 10px;
padding: 2px 10px;
box-shadow: 0 2px 9px #999;
background-color: #FFF;
border-radius: 4px;
color: #666;
/**
1. 这里显示的内容为div的title属性对应的值,覆盖了原生的title属性
2. attr(x)中的x不一定非得使用原生的标签属性title,可以随便叫,只要与能在标签中的属性x对应就行
*/
content: attr(title);
z-index: 2;
line-height: 20px;
height: 20px;
}