html - 工具提示框向上而不是底部显示
问题描述
这是我的代码
.tooltip1 {
position: relative;
display: inline-block;
}
/* Tooltip text */
.tooltip1 .tooltiptext1 {
visibility: hidden;
width: 270px;
background-color: #555;
color: #fff;
text-align: center;
padding: 5px 0;
border-radius: 6px;
/* Position the tooltip text */
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
/* Fade in tooltip */
opacity: 0;
transition: opacity 0.3s;
}
/* Tooltip arrow */
.tooltip1 .tooltiptext1::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Show the tooltip text when you mouse over the tooltip container */
.tooltip1:hover .tooltiptext1 {
visibility: visible;
opacity: 1;
}
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
我如何定位它以使其在底部打开。另外,因为它在顶部打开,如果我在 span 中添加了太多数据,那么它会在页面上方并且无法滚动,因此某些部分不可见。工具提示中是否也有解决此问题的方法?
解决方案
试试这个,
改变这种风格,
.tooltip .tooltiptext {
top: 150%; // bottom: 125%; given already
}
.tooltip .tooltiptext::after {
bottom: 100%; //top: 100%; given already
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
top: 150%;
left: 50%;
margin-left: -60px;
}
.tooltip .tooltiptext::after {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent black transparent;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
推荐阅读
- javascript - 拆分并保留数组中的子字符串
- javascript - 如何使用 Vue.js 做多个嵌套路由?
- javascript - 使用 MYSQL 加载谷歌标记
- mysql - 根据“sum”列将一行拆分为多行
- python - 为什么不让我将列表转换为字符串?
- java - --add-modules 用于 Java11 的标志替换
- html - 将页面内容文本设置为全宽?
- javascript - 使用 Cloud Firestore 的 Ionic App - 查看所有用户的数据
- c# - 如何从 CalendarDatePicker 仅将日期和月份转换为字符串
- jquery - 单击 Buster Captcha Solver 扩展的按钮