Skip to content

Commit 3afc583

Browse files
authored
Random Color Generator
1 parent c03ab4b commit 3afc583

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

randomColorGenerator/index.css

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
3+
body{
4+
margin:0;
5+
padding: 0;
6+
box-sizing: border-box;
7+
text-align: center;
8+
background: rgb(17,157,214);
9+
background: radial-gradient(circle, rgba(17,157,214,1) 0%, rgba(148,187,233,1) 100%);
10+
}
11+
12+
.main{
13+
height: 100vh;
14+
display: grid;
15+
grid-template-columns: 1fr;
16+
align-items: center;
17+
margin: 0 20vw;
18+
19+
}
20+
21+
.head{
22+
font-size:3rem;
23+
font-weight: bold;
24+
}
25+
26+
.demo{
27+
display: flex;
28+
justify-content: center;
29+
align-items:center;
30+
gap:50px
31+
}
32+
33+
#rgb{
34+
background-color: black;
35+
color: white;
36+
width: max-content;
37+
padding: 10px;
38+
margin: 0 auto;
39+
border-radius: 4px;
40+
}
41+
42+
#clrblock{
43+
height: 200px;
44+
width: 200px;
45+
background-color: white;
46+
border: 3px solid black;
47+
border-radius: 10px;
48+
}
49+
50+
.demo button{
51+
width: max-content;
52+
height: max-content;
53+
padding: 10px;
54+
cursor: pointer;
55+
border-radius: 5px;
56+
}
57+
.demo button:active{
58+
background-color: black;
59+
color: white;
60+
}
61+
62+
63+
@media screen and (max-width:580px) {
64+
.main{
65+
margin: 0 10vw;
66+
}
67+
#clrblock{
68+
width: 100px;
69+
height: 100px;
70+
}
71+
}

randomColorGenerator/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="index.css">
9+
<title>Random Color Generator</title>
10+
</head>
11+
12+
<body>
13+
<div class="main">
14+
<div class="head">Random Color Generator</div>
15+
<div>This app will let you generate a random color to any element you want on click of a button.
16+
This can generate random rgb color upto 16,777,216 different possible colors.</div>
17+
<div style="font-size: 40px; font-weight:bold">Demo</div>
18+
<div id="rgb">rgb(255, 255, 255)</div>
19+
<div class="demo">
20+
<div id="clrblock"></div>
21+
<button onclick="generateRandomColor()">Gererate Color</button>
22+
</div>
23+
</div>
24+
25+
<script src="./index.js"></script>
26+
</body>
27+
28+
</html>

randomColorGenerator/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const colorBlock = document.querySelector("#clrblock") //Target the element you want to generate random color
2+
const rgbText= document.querySelector("#rgb")
3+
4+
function generateRandomColor(){
5+
const a = Math.round(Math.random()*255)
6+
const b = Math.round(Math.random()*255)
7+
const c = Math.round(Math.random()*255)
8+
9+
colorBlock.style.backgroundColor=`rgb(${a},${b},${c})`
10+
rgbText.innerHTML=`rgb(${a}, ${b}, ${c})`
11+
}

0 commit comments

Comments
 (0)