css制作烛光
使用CSS制作烛光效果
通过CSS的动画和滤镜效果可以模拟烛光的摇曳和发光效果。以下是一种实现方法:
HTML结构
<div class="candle">
<div class="flame"></div>
</div>
CSS样式
.candle {
position: relative;
width: 60px;
height: 120px;
background: #e5a971;
border-radius: 5px;
}
.flame {
position: absolute;
top: -40px;
left: 20px;
width: 20px;
height: 40px;
background: #ff9a00;
border-radius: 50% 50% 20% 20%;
box-shadow: 0 0 20px #ff6600,
0 0 40px #ff6600,
0 0 60px #ff6600;
animation: flicker 1s infinite alternate;
}
@keyframes flicker {
0%, 100% {
transform: scale(1);
opacity: 1;
}
50% {
transform: scale(1.1);
opacity: 0.8;
}
}
增强烛光效果
为了更逼真的效果,可以添加多层火焰和更复杂的动画:
.flame::before {
content: '';
position: absolute;
top: -10px;
left: 5px;
width: 10px;
height: 20px;
background: #fffacd;
border-radius: 50%;
filter: blur(5px);
}
.flame::after {
content: '';
position: absolute;
top: -5px;
left: 2px;
width: 16px;
height: 30px;
background: #ffcc00;
border-radius: 50% 50% 20% 20%;
filter: blur(3px);
}
@keyframes flicker {
0%, 100% {
transform: translate(0, 0) scale(1);
opacity: 1;
}
25% {
transform: translate(-1px, -1px) scale(1.05);
}
50% {
transform: translate(1px, 1px) scale(0.95);
opacity: 0.9;
}
75% {
transform: translate(1px, -1px) scale(1.1);
}
}
添加蜡烛融化效果
蜡烛顶部可以添加融化的蜡滴效果:
.candle::before {
content: '';
position: absolute;
top: 0;
left: 10px;
width: 10px;
height: 15px;
background: #d98b4e;
border-radius: 0 0 5px 5px;
}
.candle::after {
content: '';
position: absolute;
top: 5px;
left: 15px;
width: 5px;
height: 10px;
background: #d98b4e;
border-radius: 0 0 3px 3px;
}
这些CSS技巧组合起来可以创建一个生动的烛光效果,通过调整动画参数和颜色可以进一步优化视觉效果。







