Skip to content

Random Color Generator #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions randomColorGenerator/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@


body{
margin:0;
padding: 0;
box-sizing: border-box;
text-align: center;
background: rgb(17,157,214);
background: radial-gradient(circle, rgba(17,157,214,1) 0%, rgba(148,187,233,1) 100%);
}

.main{
height: 100vh;
display: grid;
grid-template-columns: 1fr;
align-items: center;
margin: 0 20vw;

}

.head{
font-size:3rem;
font-weight: bold;
}

.demo{
display: flex;
justify-content: center;
align-items:center;
gap:50px
}

#rgb{
background-color: black;
color: white;
width: max-content;
padding: 10px;
margin: 0 auto;
border-radius: 4px;
}

#clrblock{
height: 200px;
width: 200px;
background-color: white;
border: 3px solid black;
border-radius: 10px;
}

.demo button{
width: max-content;
height: max-content;
padding: 10px;
cursor: pointer;
border-radius: 5px;
}
.demo button:active{
background-color: black;
color: white;
}


@media screen and (max-width:580px) {
.main{
margin: 0 10vw;
}
#clrblock{
width: 100px;
height: 100px;
}
}
28 changes: 28 additions & 0 deletions randomColorGenerator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<title>Random Color Generator</title>
</head>

<body>
<div class="main">
<div class="head">Random Color Generator</div>
<div>This app will let you generate a random color to any element you want on click of a button.
This can generate random rgb color upto 16,777,216 different possible colors.</div>
<div style="font-size: 40px; font-weight:bold">Demo</div>
<div id="rgb">rgb(255, 255, 255)</div>
<div class="demo">
<div id="clrblock"></div>
<button onclick="generateRandomColor()">Gererate Color</button>
</div>
</div>

<script src="./index.js"></script>
</body>

</html>
11 changes: 11 additions & 0 deletions randomColorGenerator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const colorBlock = document.querySelector("#clrblock") //Target the element you want to generate random color
const rgbText= document.querySelector("#rgb")

function generateRandomColor(){
const a = Math.round(Math.random()*255)
const b = Math.round(Math.random()*255)
const c = Math.round(Math.random()*255)

colorBlock.style.backgroundColor=`rgb(${a},${b},${c})`
rgbText.innerHTML=`rgb(${a}, ${b}, ${c})`
}