html - 到达边界时的 div 悬停问题

标签 html css

我想要 div 上的悬停效果,当悬停在 div 上时我应用了底部样式并且一切正常但是当悬停 div 的边界/边缘时意味着 div 连续抽动/跳跃。

我的代码:

.traning-box {
  background: #fff;
  padding-top: 70px;
  padding-bottom: 30px;
  box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
  border-radius: 5px;
  width: 120px;
  text-align: center;
}

.traning-box:hover {
  bottom: 15px;
  position: relative;
}
<div class="traning-box">
  <p> Test box</p>
</div>

最佳答案

尝试使用:after 伪元素。当 .traning-box 上升时,:after 下降,所以光标仍然在 .traning-box 上(因为它是 :after 的父 block 。

.traning-box {
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
  padding-top: 70px;
  padding-bottom: 30px;
  position: relative;
  text-align: center;
  width: 120px;
}

.traning-box:after {
  bottom: 0;
  display: block;
  content: '';
  height: 15px;
  left: 0;
  position: absolute;
  width: 100%;
}

.traning-box:hover {
  margin-top: -15px;
}

.traning-box:hover:after {
  bottom: -15px;
}
<div class="traning-box">
  <p>Test box</p>
</div>

关于html - 到达边界时的 div 悬停问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48089975/

相关文章:

SELECT 滚动的 Javascript 控件

html - 将 DIV 中的图像作为背景,其高度小于分区(不同)

html - 多列 css 破坏了 ul 内容问题

jQuery animate() 和 CSS 过渡在同一事件上分别发生

html - 用网格显示内容

javascript - 多种预定义样式或动态更改内联样式?

javascript - 使用 Javascript 将行添加到 Google 电子表格

html - 如何通过更改选项卡更改背景颜色

javascript - 如果已访问后代节点的链接,是否可以从 DOM 中删除元素?

html - 是否有不使用 JavaScript 的点击事件?