jquery - 悬停个人资料图片后的描述文本

标签 jquery html css

我想在悬停个人资料图片后显示文本。我制作了一个“标题”标签,但它无法显示不同段落中的文本。有其他方法可以做到这一点吗?

这是我的 CSS 代码:

.tooltip {
   display:none;
   position:absolute;
   border:1px solid #333;
   background-color:#161616;
   border-radius:5px;
   padding:10px;
   color:#fff;
   font-size:12px Arial;
}

这是我的 html 代码:

<table style="width:100%">
<tr>
<td><a><img src="http://2017.igem.org/wiki/images/2/26/Andrew.PNG" width="200" height="200" class="masterTooltip" title="Name: Ching Yuet To; Major/Year: Cell and Molecular Biology/3 "></a></td>
<td><img src="http://2017.igem.org/wiki/images/d/de/Venus.PNG" width="200" height="200"></td>
<td><img src="http://2017.igem.org/wiki/images/8/84/Cathy.PNG" width="200" height="200"></td>
</tr>
</table>

<script>
$(function () {
  $(document).tooltip({
      content: function () {
          return $(this).prop('title');
      }
  });
});
</script>

最佳答案

这是另一种方法。只需对您的原始代码进行一些更改。希望这会有所帮助。

a {
  position: relative;
}
a:after {
  position: absolute;
  display: none;
  content: attr(data-tooltip);
  bottom: 0;
  border: 1px solid #333;
  background-color: #161616;
  border-radius: 5px;
  padding: 10px;
  color: #fff;
  font-size: 12px Arial;
}
a:hover:after {
  display: block;
}
<table style="width:100%">
<tr>
<td><a data-tooltip="Name: Ching Yuet To; Major/Year: Cell and Molecular Biology/3"><img src="http://2017.igem.org/wiki/images/2/26/Andrew.PNG" width="200" height="200" class="masterTooltip"></a></td>
  <td><a data-tooltip="Tooltip"><img src="http://2017.igem.org/wiki/images/d/de/Venus.PNG" width="200" height="200"></a></td>
  <td><a data-tooltip="Tooltip"><img src="http://2017.igem.org/wiki/images/8/84/Cathy.PNG" width="200" height="200"></a></td>
</tr>
</table>

关于jquery - 悬停个人资料图片后的描述文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45749854/

相关文章:

jquery - 嵌套 jQuery IF 语句不起作用

javascript - HTML 链接会像表单一样下拉菜单?

javascript - 我如何使用 browser.findElements() 来计算和遍历元素?

html - 如何确保 block 元素在表格中位于同一行?

javascript - 使用 Javascript 或 jQuery 检索 session 变量的简单快速的方法?

javascript - 滚动太远

javascript - 将鼠标悬停在链接下时,将两个小时线更改为一个

javascript - 更改 anchor "position"的好方法?

javascript - 如何从 JavaScript 文档中获取第一个 <ul> 元素?

html - 特定 ID 的 CSS 媒体查询