html - 工具提示框向上显示而不是底部

标签 html css

这是我的代码

.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>

我如何定位它以使其在底部打开。此外,因为它在顶部打开,如果我在跨度中添加了太多数据,那么它会在页面上方并且无法滚动,因此某些部分不可见。工具提示中是否也有解决方法?

最佳答案

尝试这个,
改变这种风格,

.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>

关于html - 工具提示框向上显示而不是底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63753357/

相关文章:

php - 将本地站点带到实时站点 url 不起作用

css - VS2012 - CSS\9 中的验证警告

Android - 如何将 Gmail HTML 邮件解析为纯文本?

javascript - 尝试更改在 php 上重复的特定 div 宽度失败

javascript - 为什么此页面不显示音频播放器 UI?

css - Webpack 4 : file-loader not loading assets in . css 或 .scss 文件

css - 如何让这个 Bootstrap 导航栏在移动设备上看起来整洁?

html - 在可滚动的 div 中绝对定位页脚

html - 如何仅更改外部 div 中所有特定元素标签的 CSS 样式?

javascript - 在wordpress中更改背景颜色和主要内容背景