以下是实现红色心形loading特效的CSS3代码示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>红色心形Loading特效</title>
<style>
.loading-container {
position: relative;
width: 100px;
height: 100px;
transform: rotate(45deg);
}
.loading-container::before,
.loading-container::after {
content: '';
position: absolute;
top: 0;
left: 50%;
background: red;
border-radius: 100%;
animation: pulse 2s infinite ease-in-out;
}
.loading-container::before {
width: 50px;
height: 50px;
transform: translateX(-50%);
}
.loading-container::after {
width: 80px;
height: 80px;
transform: translateX(-50%);;
animation-delay: .5s;
}
@keyframes pulse {
0% {
transform: translateX(-50%) scale(.8);
opacity: 1;
}
100% {
transform: translateX(-50%) scale(1.2);
opacity: 0;
}
}
</style>
</head>
<body>
<div class="loading-container">
<div></div>
</div>
</body>
</html>
这段代码使用了CSS伪元素::before
和::after
来创建心形,通过animation
属性实现放大和淡出的动画效果,从而模拟出加载等待的场景。