<div class="box">
<a class="tooltip tooltip-up" data-msg="上提示信息"> 提示在上</a>
<a class="tooltip tooltip-down" data-msg="下提示信息"> 提示在下</a>
<a class="tooltip tooltip-left" data-msg="左提示信息"> 提示在左</a>
<a class="tooltip tooltip-right" data-msg="右提示信息"> 提示在右</a>
</div>
.box{
width:800px;
text-align:center;
margin:50px auto;
}
a{
display:inline-block;
margin:0 50px;
}
.tooltip {
position: relative;
color: #333;
text-align: center;
font-size: 14px;
cursor: pointer;
}
.tooltip:hover::before {
word-break:keep-all;
white-space:nowrap;
content: attr(data-msg);
position: absolute;
padding: 2px 6px;
display: block;
color: #333;
border: 1px solid #333;
border-radius: 5px;
font-size: 14px;
line-height:20px;
}
.tooltip:hover::after {
content: "";
position: absolute;
}
.tooltip-up:hover::before {
top: -30px;
left:50%;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
.tooltip-up:hover::after {
border-top: 5px solid #333;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
top: -5px;
left: 50%;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
.tooltip-down:hover::before {
bottom: -30px;
left:50%;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
.tooltip-down:hover::after {
border-bottom: 5px solid #333;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
bottom: -5px;
left: 50%;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
.tooltip-left:hover::before {
top: -2px;
left: -8px;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
transform: translateX(-100%);
}
.tooltip-left:hover::after {
border-left: 5px solid #333;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
top: 50%;
left:-8px;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
.tooltip-right:hover::before {
top: -2px;
right: -8px;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
transform: translateX(100%);
}
.tooltip-right:hover::after {
border-right: 5px solid #333;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
top: 50%;
right:-8px;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}