/
index.html
393 lines (363 loc) · 11.8 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>A dashingly responsive web page</title>
<style>
* {
box-sizing: border-box;
}
html,body {
height: 100%;
}
body {
font-family: Georgia, serif;
margin: 0;
padding-top: 1em;
background-color: #fff;
color: rgba(0,0,0,0.9);
font-size: calc(12px + 1vw);
line-height: 1.4;
overflow-x: hidden;
border-top: 1.5em solid #F2E4E2;
}
@media (min-width: 56.25em) {
body {
font-size: 1.3125em;
}
}
@media print {
body {
font-size: 1em;
border: 0;
}
}
/* sticky footer, but only for modern flexbox implementations
(there be IE bugs.) */
@supports (display: flex) {
body {
display: flex;
flex-direction: column;
min-height: 100vh;
}
main {
flex: 1;
}
}
code {
/* this trick is kinda weird: normalizes size of monospace fonts. */
font-family: monospace, monospace;
}
a {
color: #1E55A3;
}
footer {
margin-top: 2em;
padding: 1em;
background-color: #F2E4E2;
font-family: Avenir Next, Avenir, SegoeUI, sans-serif;
}
footer p {
font-weight: 500;
margin: 0;
}
button {
display: inline-block;
text-align: center;
border: 1px solid #142846;
border-radius: .25em;
padding: .25em 1em;
background-color: #43709F;
color: #fff;
font-size: inherit;
box-shadow: 0 .125em 0 0em #7B99B5;
-webkit-transition: all .15s;
transition: all .15s;
will-change: transform;
}
button:active,
button:focus {
border-color: #000;
background-color: #033286;
}
button:active {
-webkit-transform: translateY(.125em);
transform: translateY(.125em);
}
.wrap {
width: 95%;
margin: 0 auto;
max-width: 100rem;
}
.prose {
max-width: 38em;
}
.prose p {
margin: 0;
}
.prose p + p {
text-indent: 1.5em;
}
.prose ul {
padding-left: 1.5em;
margin: 1.4em 0;
}
.prose li + li {
margin-top: 1.4em;
}
.intro {
font-family: Avenir Next, Avenir, SegoeUI, sans-serif;
font-weight: 700;
}
@supports (initial-letter: 3) or (-webkit-initial-letter: 3) {
.prose p:nth-of-type(2)::first-letter {
-webkit-initial-letter: 3;
initial-letter: 3;
font-family: Avenir Next, Avenir, SegoeUI, sans-serif;
font-weight: 600;
color: #414956;
margin-right: .125em;
}
}
#controls {
background-color: #FAF3E7;
border-radius: 4.5em;
text-align: center;
margin: 1.4em 0;
padding: 1.4em;
max-width: 38em;
line-height: 3;
}
#controls li {
list-style: none;
display: inline-block;
}
#controls li > * {
white-space: nowrap;
}
#controls li+li:not(:first-child) {
margin-left: 1.4em;
}
@supports (flex-wrap: wrap) {
#controls {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
#controls li {
margin: 0 1.4em;
flex: 1 0 14em;
}
#controls button {
width: 100%;
}
}
/* let's draw the characters ”www” using morse code, in gradients! */
hr {
display: block;
margin: 1.4em auto;
width: 20em;
height: 2em;
border: 0;
background-image: radial-gradient(circle 1em at 18% 50%, #dae5ed 40%, transparent 0%),
radial-gradient(circle 1em at 38% 50%, #dae5ed 40%, transparent 0%),
radial-gradient(circle 1em at 60% 50%, #dae5ed 40%, transparent 0%),
radial-gradient(circle 1em at 80% 50%, #dae5ed 40%, transparent 0%),
linear-gradient(to right, #fff, #fff 60%, transparent 0%, transparent 80%, #fff 0%),
linear-gradient(transparent, transparent .6em, #dae5ed 0%, #dae5ed 1.41em, transparent 0%);
background-size: 33% 100%;
}
@media print {
hr {
height: 0;
border-bottom: 1px solid #666;
}
}
/* lots of unfocused fiddling about with the h1 starts here: */
h1 {
font-family: Avenir Next, Avenir, SegoeUI, sans-serif;
text-transform: uppercase;
font-size: 9vw;
line-height: 1.25em;
color: #21272b;
font-weight: 400;
margin: 15% 0 5%;
}
@media (min-width: 63.75em) {
h1 {
font-size: 5.75rem;
max-width: 59.625rem;
margin-left: auto;
margin-right: auto;
}
}
@media print {
h1 {
font-size: 1.8em;
margin: 0 auto;
}
}
h1 * {
display: inline-block;
position: relative;
font-weight: 400;
opacity: 0.8;
}
h1 span:first-child {
display: inline-block;
background-color: #dae5ed;
text-align: center;
color: #414956;
font-weight: 600;
padding: .85em .75em;
border-radius: 2em;
font-size: 2.2em;
margin: -.75em -.75em -.65em;
}
h1 :nth-child(2) {
/* weird one: Safari will not show the correct weight of Hoefler Text
without using the PostScript name below.
Thank FSM for Clagnut! http://clagnut.com/blog/2228 */
font-family: 'HoeflerText-Regular', Hoefler Text, Times New Roman, Times, serif;
text-transform: none;
font-style: italic;
font-weight: 200;
margin-right: -.25em;
font-size: 2.2em;
top: -.04em;
}
h1 :nth-child(3) {
display: inline-block;
-webkit-filter: url(#outlineglow);
-moz-filter: url(#outlineglow);
filter: url(#outlineglow);
width: 100%;
font-size: 1.48em;
line-height: 1;
font-weight: 700;
margin-top: -.25em;
letter-spacing: .06em;
}
h1 :nth-child(4) {
font-size: 1em;
letter-spacing: .7em;
margin-right: -1em;
position: relative;
top: -.25em;
}
/* end of fiddly stuff. */
/* make the layout a tiny bit more interesting at larger viewports: */
@media (min-width: 87.5em) {
h1 {
font-size: 5rem;
max-width: 50rem;
float: right;
-webkit-shape-outside: polygon(nonzero, 12.8% 46.9%, 8.6% 38.65%, 3.35% 24.15%, -0.45% -12.05%, 0 0, 101.6% -60.05%, 101.7% 67.6%, 15.65% 69%);
shape-outside: polygon(nonzero, 12.8% 46.9%, 8.6% 38.65%, 3.35% 24.15%, -0.45% -12.05%, 0 0, 101.6% -60.05%, 101.7% 67.6%, 15.65% 69%);
margin-left: 1.6em;
margin-top: -1.7em;
}
.prose {
margin-top: 12em;
}
body {
background-image: radial-gradient(circle 70vh at bottom right, #F8FAFF, #F8FAFF 80%, transparent 0%);
background-attachment: fixed;
}
}
@media only screen and (min-width: 100em) {
h1 {
font-size: 6rem;
max-width: 60rem;
}
}
/* Finally, here's the toggling of the Morse code stuff. */
/* hide this bit from browsers that don't understand MQ:s. */
@media only all {
.wrap, footer {
display: none;
}
#hold-the-telegraph {
font-family: monospace, monospace;
white-space: pre;
letter-spacing: .2em;
overflow: visible;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
-webkit-transform-origin: bottom left;
transform-origin: bottom left;
}
}
@media (min-width: 240px) {
#hold-the-telegraph {
display: none;
}
.wrap, footer {
display: block;
}
}
#cheatmode:target #hold-the-telegraph {
display: block;
}
#cheatmode:target .wrap,
#cheatmode:target footer {
display: none;
}
</style>
</head>
<body id="cheatmode">
<main>
<div class="wrap">
<h1>
<span>A</span>
<span>dashingly</span>
<span>responsive</span>
<span>web page</span>
</h1>
<div class="prose">
<p class="intro">Morse code, and the Telegraph, were simple in design, but changed the world. The same goes for the Web. Today’s lesson is themed around dots and dashes.</p>
<hr>
<p>We can do beautiful work with the powerful capabilities of the web platform. But neither beauty nor power lie just in the visual appearance of our sites, because the web is not just visual. It’s universal.</p>
<p>Take this simple web page, for instance. It is not just responsive on the standard ”240px plus” screens of smartphones (watches?) and up to the what-have-you widths of tablets, laptops, TVs and desktop screens.</p>
<p>No, this one goes further: it actually sort of works on screens of <code>0px</code> and up.</p>
<hr>
<p><i>”Now hold on a minute”</i> I hear you say, <i>”since the web is not just visual, any web page can work as a printed page, or using a screen reader.”</i></p>
<p>True. But this one achieves its readability on viewports with a width of about <code>1em</code> (or so) and up <em>visually</em>, and does not require a screen reader or printer to work without a screen. Sort of.</p>
<p>Let me explain:</p>
<ul>
<li>On viewports less than <code>240px</code> in width, the text contents of the page are converted to <a href="https://en.wikipedia.org/wiki/Morse_code">Morse code</a>. This encoded string of dashes and dots is then displayed vertically instead of the page content. This only requires about one em of space. I can’t imagine what kind of smartphone would have a screen like that, but hey—nobody saw the iPhone coming either. Use your favorite devtools to resize down to that width—or hit <a href="#cheatmode">cheat mode</a>.</li>
<li>You can also press the play/stop buttons (if visible) below to read that Morse code version of the page in audio form, provided you are using a reasonably modern browser. That’s right, this page can actually beepity-beep itself using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API">Audio API</a> on supported devices (don’t forget to turn the volume up. Or down, if you’re in the quiet compartment of the train), without even having a functioning screen.</li>
</ul>
<p>Apart from these features, there’s all sorts of CSS trickery and little easter eggs going on for visual stuff. CSS Shapes, feature queries, SVG filters, gradient drawings… There’s a lot you can do with 10Kb! Have a look at the <a href="https://github.com/emilbjorklund/dashingly-responsive/">GitHub repository</a> to see what’s what.</p>
</div>
</div>
<div id="hold-the-telegraph"></div>
</main>
<footer>
<p>Hastily thought up and typed by <a href="https://thatemil.com">Emil Björklund</a> (<a href="https://twitter.com/thatemil">@thatemil</a>)</p>
</footer>
<!-- poor man's <template>s... -->
<script id="buttons" type="text/x-template">
<li><button id="play">Play audio</button></li>
<li><button id="stop">Stop audio</button></li>
</script>
<script id="cheatlink" type="text/x-template">
<ul id="controls" aria-label="Control Morse code mode">
<li><a href="#cheatmode">Activate Cheat Mode for text</a></li>
</ul>
</script>
<script src="beep.js"></script>
<svg height="0">
<filter id="outlineglow">
<feMorphology in="SourceAlpha" operator="dilate" radius="5" result="outline" />
<feFlood flood-color="white" result="chroma"/>
<feComposite in="chroma" in2="outline" operator="in" result="glow" />
<feMerge>
<feMergeNode in="glow" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</svg>
</body>
</html>