css 提示
下面是完整的 CSS 提示框示例代码:
<!doctype html>
<html>
<head>
<style>
/*---1-------------------------------------------
通用
-------------------------------------------------*/
.tooltip{
position: relative;
top: 120px;
display: inline-block;
border-bottom:1px dotted black;
}
/*---2-------------------------------------------
这里是上拉文字的
-------------------------------------------------*/
.tooltiptexttop{
visibility: hidden;
width:120px;
background-color: black;
color:#fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 150%;
left: 50%;
margin-left:-60px;
}
.tooltip .tooltiptexttop::after{
content:"";
position: absolute;
top: 100%;
left:50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: black transparent transparent transparent;
}
.tooltip:hover .tooltiptexttop{
visibility: visible;
}
/*---3-------------------------------------------
这里是左拉文字的
-------------------------------------------------*/
.tooltip .tooltiptextleft{
visibility: hidden;
width:120px;
background-color: black;
color: #fff;
text-align: center;
padding: 5px 0;
position: absolute;
z-index: 1;
top: -5px;
right: 105%;
}
.tooltip:hover .tooltiptextleft{
visibility: visible;
}
/*---4-------------------------------------------
这里是下拉文字的
-------------------------------------------------*/
.tooltip .tooltiptextbottom{
visibility: hidden;
width: 120px;
background-color: #000;
color: white;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
top: 100%;
left:50%;
margin-left: -60px;
opacity: 0;
transition: opacity 1s;
}
.tooltip:hover .tooltiptextbottom{
visibility: visible;
opacity: 1;
}
/*---5-------------------------------------------
这里是右拉文字的
-------------------------------------------------*/
.tooltip .tooltiptextright{
visibility: hidden;
width:120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
top: -5px;
left: 110%;
}
.tooltip .tooltiptextright::after{
content: "";
position: absolute;
top: 50%;
right: 100%;
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent black transparent transparent;
}
.tooltip:hover .tooltiptextright{
visibility:visible;
}
</style>
</head>
<body style="text-align:center;">
<div class="tooltip">在上面的标签
<span class="tooltiptexttop">我是不是在上面</span>
</div></br>
<div class="tooltip">在左边的标签
<span class="tooltiptextleft">我是不是在做面</span>
</div></br>
<div class="tooltip">在下面的标签
<span class="tooltiptextbottom">渐渐弹出在下面</span>
</div></br>
<div class="tooltip">在右面的标签
<span class="tooltiptextright">在右面有箭头的</span>
</div>
</body>
</html>