CSS:hover尝试显示隐藏文本框时出现问题

时间:2018-05-15 19:17:21

标签: css

是的,我目前正在构建自己的网站以获得一些乐趣,我正在尝试创建一个盒子,当它悬停时会显示“x”信息。但是,对于我的生活,我无法展示这个盒子。

我想我可能还会提到我已经取得了与此相似的东西,除了在这个例子中我是在图像上而不是文本<p>

另外,每当我将鼠标悬停在文本框出现的位置时,它都能正常工作?!?!这让我很困惑!

这是我的代码:

#siteHover {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  width: 475px;
  padding: 15px;
  position: absolute;
  top: 150%;
  left: 50%;
  opacity: 0;
  transform: translate(-50%, -50%);
}

#siteHover:hover {
  opacity: 1;
}
<div class="sitevAlign">
  <p id="siteHover">This is my primary website where all the information you might require on me is available! This site is also a demonstration of my work; however, external reviews are available on the website!</p>
</div>

感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

这是你想要的吗?

如果您需要帮助了解每个代码的作用,请随时提出任何问题:)

.sitevAlign {
  height: 100px;
  width: 475px;
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 15px;
  opacity: 1;
  transform: translate(-50%, -50%);
  background-color: steelblue;
}

#siteHover {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  opacity: 0;
}

.sitevAlign:hover #siteHover {
  opacity: 1;
}
<div class="sitevAlign">
  <p id="siteHover">This is my primary website where all the information you might require on me is available! This site is also a demonstration of my work; however, external reviews are available on the website!</p>
</div>

答案 1 :(得分:0)

您的问题是,您从顶部推送div.sitevAlign 150%,因此您无法将鼠标悬停在它上面,直到向下滚动它,尝试向下滚动并将鼠标放在中间水平。

如果您将top:150%

删除它会更好

&#13;
&#13;
#siteHover {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  width: 475px;
  padding: 15px;
  position: absolute;
  left: 50%;
  opacity: 0;
  transform: translate(-50%, -50%);
}

#siteHover:hover {
  opacity: 1;
}
&#13;
<div class="sitevAlign">
  <p id="siteHover">This is my primary website where all the information you might require on me is available! This site is also a demonstration of my work; however, external reviews are available on the website!</p>
</div>
&#13;
&#13;
&#13;

作为旁注,如果您让用户知道将鼠标悬停在哪里会更好。

&#13;
&#13;
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.sitevAlign {
  border: 1px solid;
  position: relative;
  width: max-content;
  height: max-content;
  margin: 0 auto;
}

#siteHover {
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  width: 475px;
  padding: 15px;
  left: 50%;
  opacity: 0;
}

#siteHover:hover {
  opacity: 1;
}
&#13;
<div class="sitevAlign">
  <p id="siteHover">This is my primary website where all the information you might require on me is available! This site is also a demonstration of my work; however, external reviews are available on the website!</p>
</div>
&#13;
&#13;
&#13;