About
Explore
Events & Classes
Support Us
Join
Sign In
emma-the-artist
View Project Page
Run
Fullscreen
color clashe
HTML
CSS
JS
<!DOCTYPE HTML> <html> <head> <title>Page Title</title> <meta charset="utf-8"> <meta name="author" content="emma-the-artist"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h1>color clashe</h1> <button type="button" class="hexBtn">generate colors</button> <div class="palette"> <div class="color" id="color_one"><span class="hex1">#32a852</span></div> <div class="color" id="color_two"><span class="hex2">#4287f5</span></div> <div class="color" id="color_three"><span class="hex3">#eb4034</span></div> <div class="color" id="color_four"><span class="hex4">#fcba03</span></div> <div class="color" id="color_five"><span class="hex5">#c177e6</span></div> <div class="color" id="color_six"><span class="hex6">#d8eb5e</span></div> </div> </body> </html>
@import url('https://fonts.googleapis.com/css2?family=Varela+Round&display=swap'); *:focus { outline: none; } body { font-family: 'Varela Round'; overflow: hidden; } .hex { font-size: 3rem; } .hexBtn { border-radius: 7px; color: white; border: 1px solid orange; background-color: rgba(0,0,0,0.6); font-size: 1.6rem; padding: 0.25rem 0.5rem; cursor: pointer; } .palette { display: flex; flex-wrap: wrap; text-align: center; } .color { height: 30%; position: absolute; width: 30%; margin: -10px; top: 26%; font-size: 30px; margin-left: 5px; padding: 10px; } #color_one { background-color: #32a852; } #color_two { background-color: #4287f5; left: 33%; } #color_three { background-color: #eb4034; left: 65%; } #color_four { background-color: #fcba03; top: 59.9%; } #color_five { background-color: #c177e6; top: 59.9%; left: 33%; } #color_six { background-color: #d8eb5e; top: 59.9%; left:65%; }
const hexNumbers = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f']; const hexBtn = document.querySelector('.hexBtn'); const color1 = document.querySelector('#color_one'); const color2 = document.querySelector('#color_two'); const color3 = document.querySelector('#color_three'); const color4 = document.querySelector('#color_four'); const color5 = document.querySelector('#color_five'); const color6 = document.querySelector('#color_six'); const hex1 = document.querySelector('.hex1'); const hex2 = document.querySelector('.hex2'); const hex3 = document.querySelector('.hex3'); const hex4 = document.querySelector('.hex4'); const hex5 = document.querySelector('.hex5'); const hex6 = document.querySelector('.hex6'); hexBtn.addEventListener('click', getHex); function getHex() { let hexCol1 = '#'; for(let i = 0; i < 6; i++) { let random = Math.floor(Math.random()*hexNumbers.length); hexCol1 += hexNumbers[random]; } let hexCol2 = '#'; for(let i = 0; i < 6; i++) { let random = Math.floor(Math.random()*hexNumbers.length); hexCol2 += hexNumbers[random]; } let hexCol3 = '#'; for(let i = 0; i < 6; i++) { let random = Math.floor(Math.random()*hexNumbers.length); hexCol3 += hexNumbers[random]; } let hexCol4 = '#'; for(let i = 0; i < 6; i++) { let random = Math.floor(Math.random()*hexNumbers.length); hexCol4 += hexNumbers[random]; } let hexCol5 = '#'; for(let i = 0; i < 6; i++) { let random = Math.floor(Math.random()*hexNumbers.length); hexCol5 += hexNumbers[random]; } let hexCol6 = '#'; for(let i = 0; i < 6; i++) { let random = Math.floor(Math.random()*hexNumbers.length); hexCol6 += hexNumbers[random]; } color1.style.backgroundColor = hexCol1; hex1.innerHTML = hexCol1; color2.style.backgroundColor = hexCol2; hex2.innerHTML = hexCol2; color3.style.backgroundColor = hexCol3; hex3.innerHTML = hexCol3; color4.style.backgroundColor = hexCol4; hex4.innerHTML = hexCol4; color5.style.backgroundColor = hexCol5; hex5.innerHTML = hexCol5; color6.style.backgroundColor = hexCol6; hex6.innerHTML = hexCol6; }