CSS提示工具

效果展示:

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>提示工具</title>
</head>
<style>
body div{
    border: 1px solid black;
    background-color: rgb(204, 112, 112);
    color: #fff;
    margin: 10px;
}
.tooltip {/* Tooltip 容器 */
    position: relative;/*子绝父相*/
    display: inline-block;
    border-bottom: 1px dotted black; /* 悬停元素上显示点线 */
}

.tooltip .tooltiptext {/* Tooltip 文本 */
    visibility: hidden;
    width: 120px;
    background-color: black;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;

    /* 定位 */
    position: absolute;
    z-index: 1;
}
.L{
    right:  105%;
    top: -5px;
}
.U{
    bottom: 130%;
    left: 0%; 
    /* bottom: 100%;
    left: 50%; 
    margin-left: -60px; 使用一半宽度 (120/2 = 60) 来居中提示工具 */
}
.D{
    top: 130%;
    left: 0%;
    /* top: 130%;
    left: 50%;
    margin-left: -60px; */
}
.R{
    left: 105%;
    top:-5px;
}

/*右侧提示框/左侧箭头:*/
.tooltip .R::after {
    content: " ";
    position: absolute;

    top: 50%; 
    right: 100%;
    margin-top: -5px;
    border-color: transparent black transparent transparent;/*上 右 下左 顺时针*/

    border-width: 5px;
    border-style: solid;
    
}
/*底部提示框/顶部箭头:*/
.tooltip .D::after {
    content: " ";
    position: absolute;

    bottom: 100%;
    left: 50%;
    margin-left: -5px;
    border-color: transparent transparent black transparent;/*上右 下 左*/

    border-width: 5px;
    border-style: solid;
    
}
/*顶部提示框/底部箭头:*/
.tooltip .U::after {
    content: " ";
    position: absolute;

    top: 100%; 
    left: 50%;
    margin-left: -5px;
    border-color: black transparent transparent transparent;/* 上 右下左*/

    border-width: 5px;
    border-style: solid;
    
}
/*左侧提示框/右侧箭头:*/
.tooltip .L::after {
    content: " ";
    position: absolute;

    top: 50%; 
    left: 100%;
    margin-top: -5px;
    border-color: transparent transparent transparent black;/*上右下 左 */

    border-width: 5px;
    border-style: solid;
   
}

.tooltip:hover .tooltiptext {/* 鼠标移动上去后显示提示框 */
    visibility: visible;
}
</style>
<body style="text-align:center;">
<br>
<div class="tooltip">鼠标移动到这-左
  <span class="tooltiptext L">提示文本</span>
</div>
<div class="tooltip">鼠标移动到这-上
    <span class="tooltiptext U">提示文本</span>
</div>
<div class="tooltip">鼠标移动到这-下
    <span class="tooltiptext D">提示文本</span>
</div>
<div class="tooltip">鼠标移动到这-右
    <span class="tooltiptext R">提示文本</span>
</div>
</body>
</html>

CSS提示工具icon-default.png?t=M666https://www.runoob.com/css/css-tooltip.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

平平无奇的CV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值