Spaces:
Running
Running
| class CustomNavbar extends HTMLElement { | |
| connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| nav { | |
| background: white; | |
| padding: 1rem 2rem; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| box-shadow: 0 2px 4px rgba(0,0,0,0.05); | |
| position: sticky; | |
| top: 0; | |
| z-index: 50; | |
| } | |
| .logo { | |
| color: #ef4444; | |
| font-weight: bold; | |
| font-size: 1.5rem; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| } | |
| ul { | |
| display: flex; | |
| gap: 1.5rem; | |
| list-style: none; | |
| margin: 0; | |
| padding: 0; | |
| } | |
| a { | |
| color: #4b5563; | |
| text-decoration: none; | |
| font-weight: 500; | |
| transition: color 0.2s; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.25rem; | |
| } | |
| a:hover { | |
| color: #ef4444; | |
| } | |
| .active { | |
| color: #ef4444; | |
| } | |
| .menu-btn { | |
| display: none; | |
| background: none; | |
| border: none; | |
| color: #ef4444; | |
| font-size: 1.5rem; | |
| cursor: pointer; | |
| } | |
| @media (max-width: 768px) { | |
| ul { | |
| display: none; | |
| position: absolute; | |
| top: 100%; | |
| left: 0; | |
| right: 0; | |
| background: white; | |
| flex-direction: column; | |
| padding: 1rem; | |
| box-shadow: 0 4px 6px rgba(0,0,0,0.1); | |
| } | |
| ul.active { | |
| display: flex; | |
| } | |
| .menu-btn { | |
| display: block; | |
| } | |
| } | |
| </style> | |
| <nav> | |
| <a href="/" class="logo"> | |
| <i data-feather="droplet"></i> | |
| Crimson Canvas | |
| </a> | |
| <button class="menu-btn"> | |
| <i data-feather="menu"></i> | |
| </button> | |
| <ul> | |
| <li><a href="/" class="active"><i data-feather="home"></i> Home</a></li> | |
| <li><a href="#"><i data-feather="image"></i> Portfolio</a></li> | |
| <li><a href="#"><i data-feather="info"></i> About</a></li> | |
| <li><a href="#"><i data-feather="mail"></i> Contact</a></li> | |
| </ul> | |
| </nav> | |
| `; | |
| const menuBtn = this.shadowRoot.querySelector('.menu-btn'); | |
| const menu = this.shadowRoot.querySelector('ul'); | |
| menuBtn.addEventListener('click', () => { | |
| menu.classList.toggle('active'); | |
| }); | |
| } | |
| } | |
| customElements.define('custom-navbar', CustomNavbar); |