Elegant Night Select Box - 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>Elegant Night Select Box</title> <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet"> <style> body { font-family: 'Montserrat', sans-serif; background: linear-gradient(to right, #0f2027, #203a43, #2c5364); display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .select-box { position: relative; width: 280px; margin: 50px; } .select-box select { display: none; /* Hide default select */ } .select-box .custom-select { background-color: #2c5364; /* border-radius: 25px; */ border: 1px solid #ddd; padding: 10px 20px; font-size: 16px; color: #ffffff; cursor: pointer; position: relative; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); transition: all 0.3s ease; } .select-box .custom-select:hover { box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3); } .select-box .custom-select::after { content: '🌙'; font-size: 18px; margin-left: 10px; } .select-box .select-options { position: absolute; top: 100%; left: 0; right: 0; margin-left: 0; padding-left: 0; background-color: #2c5364; border: 1px solid #ddd; margin-top: 5px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 10; opacity: 0; visibility: hidden; transform: translateY(-20px); transition: all 0.3s ease; } .select-box.active .select-options { opacity: 1; visibility: visible; transform: translateY(0); } .select-box .select-options li { list-style: none; padding: 10px 20px; font-size: 16px; color: #ffffff; cursor: pointer; transition: all 0.3s ease; } .select-box .select-options li:hover { background-color: #34536b; } .select-box .select-options li.selected { background-color: #466d8a; } </style> </head> <body> <div class="select-box"> <div class="custom-select">Choose an option</div> <ul class="select-options"> <li data-value="1">Stars <span class="emoji">⭐</span></li> <li data-value="2">Moon <span class="emoji">🌕</span></li> <li data-value="3">Night Sky <span class="emoji">🌌</span></li> </ul> <select> <option value="1">Stars</option> <option value="2">Moon</option> <option value="3">Night Sky</option> </select> </div> <script> document.addEventListener('DOMContentLoaded', function() { const selectBox = document.querySelector('.select-box'); const customSelect = selectBox.querySelector('.custom-select'); const selectOptions = selectBox.querySelector('.select-options'); const options = selectOptions.querySelectorAll('li'); const select = selectBox.querySelector('select'); customSelect.addEventListener('click', function() { selectBox.classList.toggle('active'); }); options.forEach(option => { option.addEventListener('click', function() { const value = option.getAttribute('data-value'); const text = option.textContent; customSelect.innerHTML = text + ' <span class="emoji">' + option.querySelector('.emoji').textContent + '</span>'; selectBox.classList.remove('active'); options.forEach(opt => opt.classList.remove('selected')); option.classList.add('selected'); select.value = value; }); }); document.addEventListener('click', function(e) { if (!selectBox.contains(e.target)) { selectBox.classList.remove('active'); } }); }); </script> </body> </html>