html - 停止工具提示跨度在 CSS 中的每个单词处换行

标签 html css tooltip

我已经创建了当某些链接悬停时出现的工具提示。工具提示跨度为 tooltiptext 类,链接使用 ID gloss

问题是工具提示最终成为其中最长单词的宽度。我试过设置最小宽度,但这是不切实际的,因为一些工具提示只有几个词,而其他的则是整段。如果有一段文本,我不希望所有文本都在同一行,所以 white-space: nowrap 也是不切实际的。

有什么想法吗?

#gloss {
  border-bottom: solid 1pt blue;
  position: relative;
  display: inline-block;
  text-decoration: none;
}

#gloss:hover {
  text-decoration: none;
}

.tooltiptext {
  visibility: hidden;
  text-align:center; background-color:#8899ff;
  color: #000;
  border-radius: 6px;
  box-shadow: 2px 2px 1px #aaa;
  border: 1px solid #000;
  padding: 5px;
  position: absolute;
  z-index: 1;
  bottom: 125%;
  left: 50%;
  margin-left: -60px;
  opacity: 0;
  transition: all 0.15s ease;
  pointer-events: none;
}

#gloss:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}
<br><br><br><br><br>
<!--<br>s to move the paragraph down-->
<p>This is some text, with a <a href="#" id="gloss">link<span class="tooltiptext">Here is some information about the link.</span></a>. And the text continues.</p>

最佳答案

style="width: auto;" 添加到您的 span 标签中它会起作用

<br><br><br><br><br>
<!--<br>s to move the paragraph down-->
<p>This is some text, with a <a href="#" id="gloss">link<span style="width: auto;" class="tooltiptext">Here is some information about the link</span></a>. And the text continues.</p>

关于html - 停止工具提示跨度在 CSS 中的每个单词处换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690631/

相关文章:

html - 如何让 horizo​​ntal-card-footer div 位于其他 div 的正下方而不是在右侧

javascript - HTML5 Javascript SWITCH 未在 head 或 body 中运行

CSS vertical-align,如何去除文本下方的小间距?

javascript - 将元素宽度设置为元素宽度百分比宽度在页面加载时不正确

javascript - 如何自定义 Chart.js 2.0 圆环图的工具提示?

javascript - 定时文本交换?

javascript - 如何在 plotBand 上显示工具提示或图例?

jquery - 在 SharePoint 2010 中如何使用 jQuery 为所有 <a> 标记添加目标 ="_blank"

c# - 更改 slider 缩略图工具提示的文本/数据格式

tooltip - 图表上任意位置的 Chart.js 工具提示