首页 > 解决方案 > 工具提示框向上而不是底部显示

问题描述

这是我的代码

.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 中添加了太多数据,那么它会在页面上方并且无法滚动,因此某些部分不可见。工具提示中是否也有解决此问题的方法?

标签: htmlcss

解决方案


试试这个,

改变这种风格,

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


推荐阅读