css - 悬停图像上的文本过渡
问题描述
我正在尝试像这样在悬停图像上的文本上设置 css 过渡-> https://victorthemes.com/themes/glazov/portfolio-grid/
我试图用cubic-bezier()函数来做到这一点,但没有结果。
这是我的代码。
* {
margin: 0;
padding: 0;
border: 0;
}
.img__wrap {
position: relative;
height: 200px;
width: 257px;
}
.img__description {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
visibility: hidden;
opacity: 0;
transition: opacity .2s, visibility .2s;
}
.img__wrap:hover .img__description {
visibility: visible;
opacity: 1;
}
<div class="img__wrap">
<img class="img__img" src="http://placehold.it/257x200.jpg" />
<p class="img__description">Teext.</p>
</div>
请给我一些提示如何做到这一点。
解决方案
要使图像变暗,您需要更改它的不透明度。要缩放图像,请使用缩放变换并移动标题文本,您需要 translateX 变换。应用这些 css 样式和它们各自的过渡(您需要在图像和文本中进行过渡),然后剩下以下内容:
* {
margin: 0;
padding: 0;
border: 0;
}
.img__wrap {
position: relative;
background: black;
height: 200px;
width: 257px;
overflow: hidden;
}
.img__img {
opacity: 1;
transition: all 0.2s;
}
.img__description {
position: absolute;
color: #fff;
transition: all .2s;
left: 15px;
right: 0;
bottom: 15px;
transform: translateX(-100%);
}
.img__wrap:hover .img__img {
opacity: 0.5;
transform: scale(1.2);
}
.img__wrap:hover .img__description {
transform: translateX(0);
}
<div class="img__wrap">
<img class="img__img" src="http://placehold.it/257x200.jpg" />
<p class="img__description">Teext.</p>
</div>
推荐阅读
- database-normalization - 证明无损或有损分解
- git - 无法将文件推送到远程存储库
- python - 如何找到 200 到 400 之间的友好数字?
- json - 将 JSON 数组和键转换为 JSON dict
- java - 如何在 Gradle 模块之间共享单个包或类?
- java - 用于电子邮件验证的正则表达式,包括有效的空白字段
- c - 为什么 switch 语句中的 case 1 不起作用?
- javascript - 如何使用两个返回语句在 React 组件中设置三元运算符“加载”Div?
- mysql - 如果满足条件则更新一行或使用 mysql 5.7.22 中的触发器插入包含数据的新行
- android - 如何在 xamarin 中使用嵌套的 recyclerviews?