-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackGroundColourChanger.html
More file actions
77 lines (69 loc) · 1.88 KB
/
backGroundColourChanger.html
File metadata and controls
77 lines (69 loc) · 1.88 KB
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
<!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">
<title>Background Changer</title>
<style>
body,
html {
padding: 0;
margin: 0;
height: 100%;
}
.bg {
width: 100%;
height: 100%;
position: relative;
z-index: 1;
padding: 0;
margin: 0;
background-color: #fff;
}
.button-box {
display: flex;
align-items: center;
justify-content: center;
flex-flow: column;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 200px;
padding: 2rem;
background-color: #fff;
box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
border-radius: 8px;
z-index: 2;
}
.button-box button {
padding: 0.5rem;
border: 0;
cursor: pointer;
}
.button-box div {
font-family: 'Courier New', Courier, monospace;
padding-top: 1rem;
}
button:hover {
background-color: cornsilk;
}
</style>
</head>
<body>
<div class="bg" id="bgColor">
<div class="button-box">
<button onclick=changeBG()>Click Me</button>
<div id="bgColorId">#c4c4c4</div>
</div>
</div>
</body>
<script>
function changeBG() {
let randomColor = Math.floor(Math.random() * 16777215).toString(16);
document.getElementById("bgColorId").innerHTML = `#${randomColor}`;
document.getElementById("bgColor").style.backgroundColor = `#${randomColor}`;
}
</script>
</html>