-
Notifications
You must be signed in to change notification settings - Fork 75
/
index.html
83 lines (66 loc) · 1.48 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<title>Hex color generator</title>
<style>
body {
margin: 0;
padding: 0;
display: grid;
place-items: center;
height: 100vh;
font-size: 20px;
}
.main {
height: 400px;
width: 250px;
background: #3A3A38;
border-radius: 10px;
display: grid;
place-items: center;
color: #fff;
font-family: verdana;
border-radius: 15px;
}
#colorPicker {
background-color: none;
outline: none;
border: none;
height: 40px;
width: 60px;
cursor: pointer;
}
#box {
outline: none;
border: 2px solid #333;
border-radius: 50px;
height: 40px;
width: 120px;
padding: 0 10px;
}
</style>
</head>
<body>
<h1>Hex Color Generator</h1>
<div class="main">
<!--To select the color -->
Color Picker: <input type="color" id="colorPicker" value="#6a5acd">
<!--To display hex code of the color -->
Hex Code: <input type="text" id="box">
</div>
<script>
function myColor() {
// Get the value return by color picker
var color = document.getElementById('colorPicker').value;
// Set the color as background
document.body.style.backgroundColor = color;
// Take the hex code
document.getElementById('box').value = color;
}
// When user clicks over color picker,
// myColor() function is called
document.getElementById('colorPicker')
.addEventListener('input', myColor);
</script>
</body>
</html>