پیشنمایش زنده
کد HTML
<div class="battery-container">
<div class="battery">
<div class="battery-cap"></div>
<div class="liquid-fill">
<div class="bubble bubble1"></div>
<div class="bubble bubble2"></div>
<div class="bubble bubble3"></div>
</div>
<div class="battery-glow"></div>
</div>
</div>
کد CSS
/* Outer wrapper */
.battery-container {
position: relative;
display: flex;
justify-content: center;
padding: 40px;
}
/* Battery Body */
.battery {
position: relative;
width: 65px;
height: 140px;
background: white;
border: 4px solid #94a3b8;
border-radius: 15px;
display: flex;
align-items: flex-end;
padding: 5px;
overflow: hidden;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}
/* Battery Cap */
.battery-cap {
position: absolute;
top: -12px;
left: 50%;
transform: translateX(-50%);
width: 26px;
height: 10px;
background: #94a3b8;
border-radius: 3px 3px 0 0;
}
/* Liquid Fill (Light Mode Default) */
.liquid-fill {
width: 100%;
height: 0%;
background: #3b82f6; /* blue */
border-radius: 10px;
position: relative;
overflow: hidden;
box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
animation: charge 4s linear infinite;
}
/* Bubbles */
.bubble {
position: absolute;
background: rgba(255, 255, 255, 0.4);
border-radius: 50%;
bottom: 5px;
animation: bubble-rise 2s ease-in infinite;
}
.bubble1 {
width: 10px;
height: 10px;
left: 6px;
}
.bubble2 {
width: 14px;
height: 14px;
right: 8px;
animation-delay: 0.5s;
animation-duration: 2.5s;
}
.bubble3 {
width: 8px;
height: 8px;
left: 22px;
animation-delay: 1s;
animation-duration: 1.8s;
}
/* Glossy highlight */
.battery-glow {
position: absolute;
top: 10px;
right: 8px;
width: 10px;
height: 120px;
background: rgba(255, 255, 255, 0.25);
border-radius: 10px;
pointer-events: none;
}
/* Charge animation */
@keyframes charge {
0% {
height: 0%;
filter: hue-rotate(0deg);
}
50% {
height: 50%;
}
90% {
height: 100%;
filter: hue-rotate(45deg);
}
95% {
height: 100%;
opacity: 1;
}
100% {
height: 100%;
opacity: 0;
}
}
/* Bubble rise animation */
@keyframes bubble-rise {
0% {
transform: translateY(0);
opacity: 0;
}
20% {
opacity: 1;
}
100% {
transform: translateY(-80px);
opacity: 0;
}
}
/* ------------------------------------------------ */
/* 🔥 DARK MODE SUPPORT */
/* ------------------------------------------------ */
@media (prefers-color-scheme: dark) {
.battery {
background: #1e293b; /* slate-800 */
border-color: #475569; /* slate-600 */
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
}
.battery-cap {
background: #475569;
}
.liquid-fill {
background: #84cc16; /* lime-500 */
box-shadow: 0 0 20px rgba(132, 204, 22, 0.6);
}
.battery-glow {
background: rgba(255, 255, 255, 0.1);
}
}