-
CSS Electric Navbar Animation
HTML
CSS
JavaScript
Home
Projects
Services
About
Contact
:root { --color-bg: #090a0f; --color-nav-bg: #12141d; --color-text: #6b7280; --color-text-hover: #ffffff; --electric-cyan: #00f3ff; --electric-purple: #bc13fe; --electric-blue: #0051ff; } * { margin: 0; padding: 0; box-sizing: border-box; } body { background-color: var(--color-bg); background-image: radial-gradient(circle at 50% 0%, #1a1c29 0%, transparent 50%), linear-gradient(0deg, transparent 24%, rgba(255,255,255,0.02) 25%, rgba(255,255,255,0.02) 26%, transparent 27%, transparent 74%, rgba(255,255,255,0.02) 75%, rgba(255,255,255,0.02) 76%, transparent 77%, transparent), linear-gradient(90deg, transparent 24%, rgba(255,255,255,0.02) 25%, rgba(255,255,255,0.02) 26%, transparent 27%, transparent 74%, rgba(255,255,255,0.02) 75%, rgba(255,255,255,0.02) 76%, transparent 77%, transparent); background-size: 100% 100%, 50px 50px, 50px 50px; font-family: 'Rajdhani', sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; color: white; } .navbar { background: rgba(18, 20, 29, 0.7); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.05); padding: 1.5rem 3rem; border-radius: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(0, 243, 255, 0.02); position: relative; z-index: 10; } .nav-list { display: flex; list-style: none; gap: 3rem; } .nav-item { position: relative; } .nav-link { text-decoration: none; color: var(--color-text); font-size: 1.25rem; font-weight: 600; text-transform: uppercase; letter-spacing: 2px; padding: 0.5rem 1rem; display: block; transition: color 0.3s ease; position: relative; } /* Text glow effect on hover */ .nav-link:hover, .nav-link:focus { color: var(--color-text-hover); text-shadow: 0 0 5px var(--electric-cyan), 0 0 10px var(--electric-cyan), 0 0 20px var(--electric-blue); outline: none; } /* The base container for the flowing line to prevent overflow issues */ .nav-link::before { content: ''; position: absolute; bottom: -2px; left: 0; width: 100%; height: 3px; background: linear-gradient(90deg, transparent, var(--electric-cyan), var(--electric-purple), var(--electric-blue), transparent ); background-size: 200% auto; border-radius: 5px; opacity: 0; transform: scaleX(0); transform-origin: center; transition: transform 0.4s cubic-bezier(0.86, 0, 0.07, 1), opacity 0.4s ease; } /* Expand the line and trigger the flow animation */ .nav-link:hover::before, .nav-link:focus::before { opacity: 1; transform: scaleX(1); animation: laser-flow 1.5s linear infinite, laser-glow 2s ease-in-out infinite alternate; } /* Top decorative electric spark */ .nav-link::after { content: ''; position: absolute; top: 0; left: 50%; width: 20px; height: 2px; background: var(--electric-cyan); box-shadow: 0 0 10px var(--electric-cyan), 0 0 20px var(--electric-cyan); border-radius: 50%; opacity: 0; transform: translateX(-50%) translateY(-10px); transition: all 0.3s ease; } .nav-link:hover::after, .nav-link:focus::after { opacity: 1; transform: translateX(-50%) translateY(0); width: 60%; animation: top-spark 2s infinite alternate; } /* Animates the gradient background to look like flowing energy */ @keyframes laser-flow { 0% { background-position: 200% center; } 100% { background-position: -200% center; } } /* Makes the bottom underline pulsate its glow */ @keyframes laser-glow { 0% { box-shadow: 0 0 5px var(--electric-cyan), 0 2px 5px var(--electric-blue); } 50% { box-shadow: 0 0 15px var(--electric-cyan), 0 2px 10px var(--electric-purple), 0 0 20px var(--electric-blue); } 100% { box-shadow: 0 0 5px var(--electric-cyan), 0 2px 5px var(--electric-blue); } } /* Makes the top accent flicker slightly */ @keyframes top-spark { 0%, 100% { opacity: 0.8; width: 40%; box-shadow: 0 0 5px var(--electric-cyan); } 50% { opacity: 1; width: 80%; box-shadow: 0 0 15px var(--electric-cyan), 0 0 25px var(--electric-purple); } 70% { opacity: 0.5; width: 50%; box-shadow: 0 0 2px var(--electric-cyan); } } /* Responsive behavior */ @media (max-width: 768px) { .nav-list { gap: 1.5rem; } .nav-link { font-size: 1rem; padding: 0.5rem; } .navbar { padding: 1rem 1.5rem; } }
Live Preview