有趣的css - 点赞爱心动效按钮
以下是一个使用CSS创建点赞爱心动效按钮的示例代码:
HTML:
<div class="like-button">
<span class="like-icon"></span>
<span class="like-text">点赞</span>
</div>
CSS:
.like-button {
display: inline-block;
background-color: #e0e0e0;
border-radius: 30px;
padding: 10px 20px;
cursor: pointer;
transition: background-color 0.3s;
user-select: none;
}
.like-button:hover {
background-color: #d9534f;
}
.like-button .like-icon {
display: inline-block;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #fff;
position: relative;
margin-right: 5px;
animation: like-heart-bounce 0.5s infinite alternate;
}
.like-button .like-icon::before,
.like-button .like-icon::after {
content: '';
position: absolute;
left: 10px;
top: 0;
width: 20px;
height: 20px;
background-color: #fff;
border-radius: 50%;
}
.like-button .like-icon::before {
transform: translateX(-20px);
}
.like-button .like-icon::after {
transform: translateX(20px);
}
@keyframes like-heart-bounce {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
}
}
.like-button .like-text {
vertical-align: top;
}
这段代码创建了一个带有点赞动画的爱心形状按钮,当用户将鼠标悬停在按钮上时,按钮背景色会变化,并且爱心图标会跳动。这是一个简单的示例,可以根据需要进行样式和动画的自定义。
评论已关闭