将默认的title属性自定义为showtitle,然后对showtitle修改样式。
如果使用默认的title,默认的样式也会展示。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
p:hover {
position: relative;
cursor: pointer;
}
p[showtitle]:hover:after {
line-height: 1.25;
content: attr(showtitle);
color: #fff;
padding: 2px 8px;
position: absolute;
left: 10%;
top: 100%;
z-index: 20;
white-space: pre-wrap;
background-color: rgba(37, 39, 42, .85);
}
</style>
</head>
<body>
<p showtitle="展示悬停的样式">展示悬停的样式</p>
</body>
</html>
效果如图所示: