css - 我的动画(悬停)不工作,我不明白为什么

标签 css

我实际上正在为一个网站开发 Wordpress。 我希望我的网格在悬停图像时显示描述,但文本淡出的动画不起作用,我不明白为什么。

我是 CSS 的新手,所以这可能是一个基本错误,在互联网上我看到我们应该在没有结束的情况下将动画放在同一个元素上,我试过没有“.text-a-hover”(总是在 .el-item 中)并尝试将其直接放在 .texte-a-hover 中,但均无效

.texte-a-hover {
  border: 2px;
  visibility: hidden;
  height: 0;
}

.el-item .texte-a-hover {
  animation: out 0.5s;
}

.el-item:hover .texte-a-hover {
  visibility: visible;
  animation: in 0.5s;
  height: 100%;
  padding: 5px;
}

@keyframes in {
  0% {
    transform: translateY(-30px);
    opacity: 0;
    height: 0;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
    height: 100%;
  }
}

@keyframes out {
  0% {
    opacity: 1;
    height: 100%;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    transform: translateY(-30px);
    opacity: 0;
    height: 0;
  }
}
<p class="texte-a-hover"> text </p>

.el-item就是整组,图片+文字

所以我希望文本像淡入一样淡出

感谢您对我的关注和以后的帮助

最佳答案

关键帧在这里似乎有点矫枉过正。您可以只使用 :hover 状态和元素的一些转换。

.texte-a-hover {
  border: 2px;
  opacity: 0;
  height: 0;
  transition: opacity .5s, height .5s;
}

.el-item:hover .texte-a-hover {
  visibility: visible;
  opacity: 1;
  height: 100%;
}
<div class="el-item">XXX
  <p class="texte-a-hover"> text </p>
</div>

关于css - 我的动画(悬停)不工作,我不明白为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56019796/

相关文章:

javascript - clientHeight/clientWidth 在不同的浏览器上返回不同的值

jquery - 在浏览器调整大小时调整 div 大小

css - 溢出 : hidden; and z-index aren't able to hide an element beneath it?

javascript - 为什么 jquery 代码不能在服务器上运行但可以在我的 PC 上运行?

html - IE 没有正确对齐我的文本

html - 位置 : fixed scrolls too far

jquery - 如何将元素放入 Bootstrap 4 数据内容中?

html - 在 90% 宽度的 Div 中居中 HTML 表格

css - 使用css在图像上垂直对齐

javascript - 仅在选项卡焦点上勾勒轮廓