-
Notifications
You must be signed in to change notification settings - Fork 7
/
css-fizz-buzz.html
48 lines (48 loc) · 957 Bytes
/
css-fizz-buzz.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
<!DOCTYPE HTML>
<head>
<script>
function generate() {
event.preventDefault();
let inp = document.getElementById("target");
let target = parseInt(inp.value, 10);
inp.value = "";
let content = "";
for (let i = 1; i <= target; ++i)
content += "<div>" + i + "</div>";
document.getElementById("display").innerHTML = content;
}
</script>
<style>
#display div {
display: inline-block;
width: 5rem;
height: 5rem;
border: 1px solid black;
margin: 0.25rem;
}
#display div:nth-child(3n) {
border: 3px solid green;
font-size: 0;
}
#display div:nth-child(3n)::before {
content: "fizz";
font-size: 1rem;
}
#display div:nth-child(5n) {
background-color: #a0f0c0;
font-size: 0;
}
#display div:nth-child(5n)::after {
content: "buzz";
font-size: 1rem;
}
</style>
</head>
<body>
<form onsubmit="generate()">
<label>Enter number to fizzbuzz to: <input id=target></label>
<input type=submit value="Generate">
</form>
<div id=display></div>
</body>
</html>