html - 在悬停时使用过渡到绝对位置

标签 html css css-transitions

我试图在悬停时在 DIV 上获得过渡动画。但是,它不起作用。我觉得我错过了什么!

JSFIDDLE DEMO

HTML

<div class="profile__container">
          <img src="http://i.imgur.com/SGw04SV.jpg" class="profile__list--resume img-fluid" />
          <div class="profile__button">
            <h2>Hello World</h2>
          </div>
        </div>

CSS:

.profile__button {
  display: none;
  background: linear-gradient(to bottom, transparent 0%, #08ca77 60%);
  padding: 120px 15px 15px;
  text-transform: capitalize;
  -moz-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
}
.profile__container:hover .profile__button {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  text-align: center;
}

最佳答案

不使用 display 属性,而是使用 opacityvisibility,如下所示。

.profile__button {
  background: linear-gradient(to bottom, transparent 0%, #08ca77 60%);
  padding: 120px 15px 15px;
  text-transform: capitalize;
  transition: .5s;
  opacity: 0;
  visibility: hidden;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  text-align: center;
}
.profile__container:hover .profile__button {
  opacity: 1;
  visibility: visible;
}
<div class="profile__container">
          <img src="http://i.imgur.com/SGw04SV.jpg" class="profile__list--resume img-fluid" />
          <div class="profile__button">
            <h2>Hello World</h2>
          </div>
        </div>

关于html - 在悬停时使用过渡到绝对位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50174478/

相关文章:

javascript - 在 jQuery 中将所有 <td>content</td> 替换为 <li>content</li>

javascript - 特定分辨率时隐藏html元素

html - CSS3 过渡高度自动到 100%

html - 这个 CSS3 过渡不应该旋转吗?

css - 悬停时带有图像更改的纯 CSS slider

html - 如何创建一个与基本数据库交互的简单 Web 应用程序?

javascript - 如何在单击时关闭此菜单?

javascript - 为什么在 HTML Javascript 中使用 &lt;!-- 和//-->?

html - 如何隐藏水平滚动条但仍然可以滚动

html - 将两个 div 置于另一个 div 的中心并在它们之间包含边距