-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathcss-binary.html
145 lines (120 loc) · 2.9 KB
/
css-binary.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css binary</title>
<style>
*, *::before, *::after {
box-sizing: border-box;
}
html, body {
height: 100%;
}
body {
display: grid;
align-items: center;
justify-items: center;
height: 100%;
margin: 0;
color: #635274;
background-color: #d0e0eb;
font: 1.5rem/1 'Roboto', sans-serif;
}
.wrapper {
padding: 20px 40px;
border-radius: 15px;
background-color: #ebf7f8;
}
h1 {
margin: 0;
font-size: 2.25rem;
line-height: 1;
}
.widget-wrapper {
display: grid;
grid-template-columns: repeat(6, auto);
grid-template-rows: repeat(2, auto);
grid-auto-flow: column;
column-gap: 20px;
row-gap: 10px;
margin-top: 20px;
text-align: center;
counter-reset: sum; /* sum starts at 0 */
}
.digit, .decimal-output {
min-width: 50px;
padding: 10px;
border: 3px dashed #88abc2;
border-radius: 3px;
color: #f57576;
background-color: #fff;
font-size: 2.5rem;
}
.label {
align-self: end;
}
.digit-4 { --increment: 8; }
.digit-3 { --increment: 4; }
.digit-2 { --increment: 2; }
.digit-1 { --increment: 1; }
.digit::before {
content: '0'; /* content needs an initial value for animation to work */
animation: flip-digit step-end infinite;
animation-duration: calc(var(--increment) * 2s);
}
@keyframes flip-digit {
50% {
content: '1';
counter-increment: sum var(--increment);
}
}
.equals {
align-self: center;
font-size: 3rem;
}
/* display sum, which now has all the increments made by the binary digits */
.decimal-output::before {
content: counter(sum);
}
/* decrease a bunch of font sizes and padding on smaller screens */
@media (max-width: 540px) {
body {
font-size: 1.25rem;
}
.wrapper {
padding: 10px;
}
h1 {
font-size: 1.75rem;
}
.widget-wrapper {
column-gap: 10px;
margin-top: 15px;
}
.digit, .decimal-output {
padding: 5px;
font-size: 2.25rem;
}
}
</style>
</head>
<body>
<div class="wrapper">
<h1>CSS Binary Counter</h1>
<div class="widget-wrapper">
<div class="digit digit-4"></div>
<div class="label">2<sup>3</sup></div>
<div class="digit digit-3"></div>
<div class="label">2<sup>2</sup></div>
<div class="digit digit-2"></div>
<div class="label">2<sup>1</sup></div>
<div class="digit digit-1"></div>
<div class="label">2<sup>0</sup></div>
<div class="equals">=</div>
<div><!-- empty --></div>
<div class="decimal-output"></div>
<div class="label">decimal</div>
</div>
</div>
</body>
</html>