/
dashytka
/
Interactive_Color_Palette
Обзор
Документация
Войти
/
dashytka
/
Interactive_Color_Palette
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
html
114 строк
4 KB
dashytka
create html
29 окт 2025, 19:45
29 окт 2025, 19:45
56badd8
Код
Авторство
О чём код?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Interactive Color Palette</title> <style> body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; background-color: #f5f5f5; } .color-palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 20px 0; } .color-box { height: 100px; border-radius: 8px; cursor: pointer; transition: transform 0.2s; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; text-shadow: 1px 1px 2px rgba(0,0,0,0.5); } .color-box:hover { transform: scale(1.05); } .selected-color { margin-top: 20px; padding: 15px; border-radius: 8px; text-align: center; font-size: 18px; } button { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; margin: 5px; } button:hover { background-color: #45a049; } </style> </head> <body> <h1>Interactive Color Palette</h1> <div class="color-palette"> <div class="color-box" style="background-color: #FF6B6B;" onclick="selectColor('#FF6B6B', 'Coral Red')">Coral Red</div> <div class="color-box" style="background-color: #4ECDC4;" onclick="selectColor('#4ECDC4', 'Turquoise')">Turquoise</div> <div class="color-box" style="background-color: #45B7D1;" onclick="selectColor('#45B7D1', 'Sky Blue')">Sky Blue</div> <div class="color-box" style="background-color: #96CEB4;" onclick="selectColor('#96CEB4', 'Mint Green')">Mint Green</div> <div class="color-box" style="background-color: #FFEAA7;" onclick="selectColor('#FFEAA7', 'Light Yellow')">Light Yellow</div> <div class="color-box" style="background-color: #DDA0DD;" onclick="selectColor('#DDA0DD', 'Plum Purple')">Plum Purple</div> </div> <div> <button onclick="changeBackground()">Apply as Background</button> <button onclick="resetBackground()">Reset Background</button> </div> <div id="selectedColor" class="selected-color"> Select a color from the palette above </div> <script> let currentSelectedColor = ''; let currentColorName = ''; function selectColor(colorCode, colorName) { currentSelectedColor = colorCode; currentColorName = colorName; document.getElementById('selectedColor').innerHTML = `Selected: <strong>${colorName}</strong> (${colorCode})`; document.getElementById('selectedColor').style.backgroundColor = colorCode; document.getElementById('selectedColor').style.color = getContrastColor(colorCode); } function changeBackground() { if (currentSelectedColor) { document.body.style.backgroundColor = currentSelectedColor; } } function resetBackground() { document.body.style.backgroundColor = '#f5f5f5'; document.getElementById('selectedColor').style.backgroundColor = ''; document.getElementById('selectedColor').style.color = 'black'; document.getElementById('selectedColor').innerHTML = 'Select a color from the palette above'; } function getContrastColor(hexcolor) { const r = parseInt(hexcolor.substr(1, 2), 16); const g = parseInt(hexcolor.substr(3, 2), 16); const b = parseInt(hexcolor.substr(5, 2), 16); const brightness = ((r * 299) + (g * 587) + (b * 114)) / 1000; return (brightness > 128) ? 'black' : 'white'; } </script> </body> </html>