Special Accordion - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Special Accordion</title> <style> body { font-family: 'Helvetica', sans-serif; background: #e9ecef; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .accordion { background: #fff; border-radius: 8px; box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1); overflow: hidden; width: 100%; max-width: 600px; } .accordion-item { border-bottom: 1px solid #e5e5e5; } .accordion-item:last-child { border-bottom: none; } .accordion-header { background: #007bff; color: #fff; cursor: pointer; padding: 18px; display: flex; justify-content: space-between; align-items: center; transition: background 0.3s; } .accordion-header:hover { background: #0056b3; } .accordion-header h3 { margin: 0; font-size: 1.2rem; } .accordion-header .icon { font-size: 1.5rem; transition: transform 0.3s; } .accordion-content { background: #fff; color: #333; display: none; padding: 18px; animation: expand 0.4s forwards; } .accordion-content p { margin: 0; font-size: 1rem; } .accordion-item.active .accordion-content { display: block; } .accordion-item.active .accordion-header .icon { transform: rotate(180deg); } @keyframes expand { from { max-height: 0; opacity: 0; } to { max-height: 200px; opacity: 1; } } </style> </head> <body> <div class="accordion"> <div class="accordion-item"> <div class="accordion-header"> <h3>Section 1 <span>📈</span></h3> <span class="icon">▼</span> </div> <div class="accordion-content"> <p>Modern content for the first section goes here.</p> </div> </div> <div class="accordion-item"> <div class="accordion-header"> <h3>Section 2 <span>💡</span></h3> <span class="icon">▼</span> </div> <div class="accordion-content"> <p>Modern content for the second section goes here.</p> </div> </div> <div class="accordion-item"> <div class="accordion-header"> <h3>Section 3 <span>🌐</span></h3> <span class="icon">▼</span> </div> <div class="accordion-content"> <p>Modern content for the third section goes here.</p> </div> </div> </div> <script> document.querySelectorAll('.accordion-header').forEach(header => { header.addEventListener('click', () => { const accordionItem = header.parentElement; const isActive = accordionItem.classList.contains('active'); document.querySelectorAll('.accordion-item').forEach(item => { item.classList.remove('active'); }); if (!isActive) { accordionItem.classList.add('active'); } }); }); </script> </body> </html>