html - 如何在旋转图像上进行叠加
问题描述
我仍在学习样式并寻找解决方案,其中:
- 图像上出现从浅灰色到浅蓝绿色渐变的叠加层
- 图片放大20%(不爬出原始尺寸)顺时针旋转30度
- 动画在 300 毫秒内顺利进行
所以我让图像缩放和旋转,但叠加让我抓狂。
.zoom-effect-container {
float: left;
position: relative;
width: 300px;
height: 200px;
margin: 0 auto;
overflow: hidden;
border: 1px solid black;
}
.image-card {
position: absolute;
top: 0;
left: 0;
}
.image-card img {
-webkit-transition: 300ms ease;
transition: 300ms ease
}
.zoom-effect-container:hover .image-card img {
-webkit-transform: scale(1.2);
transform: scale(1.2) rotate(30deg);
}
<div class="zoom-effect-container">
<div class="image-card">
<img src="https://picsum.photos/300/200" />
</div>
</div>
解决方案
使用伪元素:
.image-card:before { ... }
将 CSS 渐变应用到该元素。我使用了一个生成器站点来创建这个示例。真的很容易选择你想要的任何设置:https ://colorzilla.com/gradient-editor/#e0e0e0+0,00faff+100&0+0,0.65+100
z-index
此时需要保持“层”以正确的顺序堆叠。
.zoom-effect-container {
position: relative;
width: 300px;
height: 200px;
margin: 0 auto;
overflow: hidden;
border: 1px solid black;
}
.image-card {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.zoom-effect-container:hover .image-card:before {
/* this is the overlay */
position: absolute;
z-index: 9;
content: '';
width: 100%;
height: 100%;
background: -moz-linear-gradient(top, rgba(224, 224, 224, 0) 0%, rgba(0, 250, 255, 0.65) 100%);
/* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(224, 224, 224, 0) 0%, rgba(0, 250, 255, 0.65) 100%);
/* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(224, 224, 224, 0) 0%, rgba(0, 250, 255, 0.65) 100%);
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00e0e0e0', endColorstr='#a600faff', GradientType=0);
/* IE6-9 */
}
.image-card img {
position: relative;
z-index: 1;
-webkit-transition: 300ms ease;
transition: 300ms ease;
}
.zoom-effect-container:hover .image-card img {
-webkit-transform: scale(2);
transform: scale(2) rotate(30deg);
}
<div class="zoom-effect-container">
<div class="image-card">
<img src="https://picsum.photos/300/200" />
</div>
</div>
推荐阅读
- python - 如何让 crontab 作业依赖项正常工作并避免找不到命令
- sql - psycopg2.errors.UndefinedTable:关系“functie”不存在(表确实存在)
- android-studio - 为什么YT播放器会导致App崩溃
- node.js - 在 Typescript Jest 中模拟导出的类
- java - 如何解决“SecurityManager:身份验证禁用;火花分发集群中的异常”?
- excel - Excel VBA 获取物理位置,而不是 OneDrive URL
- networking - 启用 Calico Networking 和 vxlan 模式的 Kubernetes 集群
- python - 如何将此python循环转换为列表理解?
- java - java套接字上的Docker:java.net.ConnectException:连接被拒绝(连接被拒绝)
- recaptcha - recaptcha 验证 API 始终返回 true