hex color generator
hex color generator |
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="https://kit.fontawesome.com/e64844b4a0.js" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>hex color generate</title>
</head>
<body>
<style>
@import url("https://fonts.googleapis.com/css?family=Open+Sans|Roboto:400,700&display=swap");
*{
margin: 0;
padding: 0;
font-family: "Open Sans", sans-serif;
box-sizing: border-box;
}
.container{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height:100vh;
max-width:100%;
margin: 10px;
}
.color-name{
background-color: black;
padding: 5px;
min-width: 500px;
max-width: 710px;
height: 100px;
display: flex;
justify-content: center;
align-items: center;
color:#FFF;
border-radius: 10px;
}
.color-name h1{
font-size: 50px;
font-weight: 400;
}
.color-name .color{
color:royalblue;
}
.color-btn button{
width:150px;
height: 60px;
color:#FFF;
padding: 10px;
margin: 10px;
font-size: 30px;
border-radius: 10px;
border:none;
background-color: blue;
}
.copy-color{
margin-left: 15px;
}
@media screen and (max-width: 992px) {
.color-name{
width:100%;
padding: 20px;
margin: 10px;
height: 120px;
}
}
</style>
<div class="container">
<div class="color-name">
<h1>background color: <span class="color">#fff</span></h1>
</div>
<div class="color-btn">
<button class="btn">generate</button>
</div>
</div>
</body>
<script src="src/app.js"></script>
</html>
app.js
const hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"];
const btn = document.querySelector(".btn");
const color = document.querySelector(".color");
btn.addEventListener('click', function(){
let hexcolor='#';
for(let i=0;i<6;i++)
{
hexcolor +=hex[getnumber()];
}
color.innerHTML=hexcolor;
document.body.style.backgroundColor=hexcolor;
});
function getnumber()
{
return Math.floor(Math.random() * hex.length)
}
Post a Comment
If you have any doubts, Please let me know
Thanks!