css - 复制图像并设置悬停 CSS
问题描述
我想做以下动画:
一个带有 2 个相同箭头的 div 和悬停第一个箭头应该向左/向右移动。我试图这样做,但没有成功。我正在使用 2 张图片设置背景,但是如何为 1 张图片(如 gif)设置动画?
.arrow-right2 {
content: "";
background: transparent url(https://i.imgur.com/u7cYXIo.png) 0 -185px no-repeat, transparent url(https://i.imgur.com/u7cYXIo.png) 0 -185px no-repeat;
height: 35px;
position: absolute;
top: -5%;
left: 0;
width: 35px;
}
解决方案
尝试使用具有相同箭头的 2 个不同 div,绝对位置,并使用它来重叠两个箭头。如果可以,请使用单个图像,而不是精灵。然后在其中一张图像上应用悬停效果。
body {
background: red;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 50px;
position: relative;
}
.arrow1 {
background: url('https://i.imgur.com/u7cYXIo.png') no-repeat -17px -199px;
width: 12px;
height: 24px;
display: block;
left: 0;
position: absolute;
}
.arrow2 {
background: url('https://i.imgur.com/u7cYXIo.png') no-repeat -17px -199px;
width: 12px;
height: 24px;
display: block;
position: absolute;
transition: all 0.4s;
left: 0;
}
.arrow2:hover {
left: -10px;
transition: all 0.4s;
}
<div class="container">
<div class="arrow1">
</div>
<div class="arrow2">
</div>
</div>
推荐阅读
- python - Python 日志库 - 记录其中包含双引号的消息
- azure - 如何使用用户委派 SAS 或 Azure RBAC 为 Azure Active Directory B2C 用户(自定义域)授予存储帐户容器的权限?
- c++ - 将 CUDA 类集成到 C++ 程序中
- javascript - 选择将下载文件的文件夹(REACTJS)
- python - 通过传入字符串或其他对象,使用 loc 选择 Pandas DataFrame 中的所有行
- c# - 如何在winform中获取按钮的名称?
- r - 在 R 中将 JSON 对象格式化为数据框
- bash - bash,键值对确定正在使用的包管理器
- ios - Swift 未获取数据 Firebase RTDB
- r - 与列表不匹配时如何有条件地添加数据行