html - 工具提示的 CSS 可见性规则不起作用
问题描述
显示:无;与可见性:隐藏;
我知道“显示:无;” 不会占用空间和“可见性:隐藏;” 隐藏时会占用空间。
那为什么这个工具提示是由“可见性:隐藏;”定义的?不占空间?它的行为类似于“显示:无;”
简而言之,工具提示不应该与它下面的文本重叠,对吧?
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
<!DOCTYPE html>
<html>
<body style="text-align:center;">
<div class="tooltip">Hover over me
<div class="tooltiptext">Tooltip text</div>
</div>
<p>Note that the tooltip is overlapping the text beneath it. The text should appear below the tooltip position, right?</p>
</body>
</html>
解决方案
删除这部分代码。你会看到区别
/* Position the tooltip */
position: absolute;
推荐阅读
- javascript - React - 使用 Redux 状态填充第一个选择选项
- database - 如何提取和组合hive数据库中的特定数据表。发现一些错误
- asp.net - Asp.Net.Core 完全自定义
- javafx - 使用 Guice 4 的 createInjector() 时出现 InvocationTargetException
- python - 如何将变量保存到文件中(如打印但保存到文件中)?
- python - 为什么在除块之外的python中包含错误类型会减少运行时间?
- python - 自定义损失函数:NotImplementedError:无法将符号张量(truediv_2:0)转换为 numpy 数组
- sql - 用于返回分隔字符串不匹配的行的 SQL 表达式
- python-3.x - 我如何从 transfermarkt 上的玩家那里抓取多个国家/地区的图像并且仍然避免双重国籍?
- javascript - 我将如何使用 Discord.js 制作一个“主持活动”的机器人?