【问题标题】:Adding tooltip hover to an image with css使用 css 将工具提示悬停添加到图像
【发布时间】:2017-08-30 14:35:19
【问题描述】:

我想创建一个工具提示(使用 css),一旦用户将鼠标移到元素上就会出现。我让它适用于文本,但我无法让它适用于图像。

.container {
  position: relative;
  width: 15%;
}

.image {
  position: relative;
  display: inline-block;
  width: 100%;
  height: auto;
}
.image .tooltiptext2 {
  visibility: hidden;
  width: 150%;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  top: -8px;
  left: 110%;
  font-size: 150%;
  font-family: Arial;

/* Fade in tooltip - takes 1 second to go from 0% to 100% opac: */
  opacity: 0;
  transition: opacity 1s;
}

.image .tooltiptext2::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 100%;
  margin-top: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent black transparent transparent;
}
.image:hover .tooltiptext2 {
    visibility: visible;
    opacity: 1;
}

你可以在这个链接中看到我做了什么:

https://jsfiddle.net/Ruloco/q3e4psh3/

我会感谢你能给我的任何帮助。提前致谢!!

【问题讨论】:

    标签: html css image hover tooltip


    【解决方案1】:

    .tooltiptext2 不是.image 的子级。使用 .image + .tooltiptext2 而不是 .image .tooltiptext2 可以使工具提示起作用。

    https://jsfiddle.net/8Lmz2oLj/

    【讨论】:

      【解决方案2】:

      工具提示不是图像的子项。您需要修改样式,以便图像容器是您正在监听的内容。

      .container:hover .tooltiptext2 {
          visibility: visible;
          opacity: 1;
      }
      

      https://jsfiddle.net/q3e4psh3/1/

      【讨论】:

        猜你喜欢
        • 2016-08-23
        • 2015-05-07
        • 2018-08-10
        • 1970-01-01
        • 2015-09-28
        • 2015-12-07
        • 1970-01-01
        • 1970-01-01
        • 2014-02-12
        相关资源
        最近更新 更多