-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP02-styles.css
423 lines (306 loc) · 9.59 KB
/
P02-styles.css
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/*=================================================
PART 2: Now let's add some CSS style to our game!
First we are gonna pick a nice pixel art font
from Google Fonts, it's free and easy to use.
The code below imports the font woff file,
you can grab this code from the Google Fonts
website or you can use their pre made CSS.
https://fonts.google.com/
=================================================*/
@font-face {
font-family: "Silkscreen";
font-style: normal;
font-weight: 400;
font-display: swap;
src: url(font/Silkscreen.woff2) format("woff2")
}
.ui a,
.ui h1,
.ui label,
.ui button {
font-family: "Silkscreen", monospace;
}
/*=================================================
The body element will have no margin or padding and
will paint all the screen with a black color.
In CSS the unit "1vw" is equivalent to 1% of the
window inner width, and "vh" is equivalent to 1%
of the height. We use "svh" to refer to the
smalles viewport and avoid mobile menus.
https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units
To hide all scroll bars we use overflow: hidden.
=================================================*/
body {
margin:0;
padding:0;
width: 100vw;
height: 100svh;
background: black;
overflow: hidden;
}
/*=================================================
Remember the body only have one child that will be
rendered on screen, the container element.
Inside the container we have our "canvas.screen"
and the user interface. We want them to be rendered
on top of each other, to achieve this we will
use the grid property.
Read more about it in this useful article:
https://css-tricks.com/snippets/css/complete-guide-grid/
Let's add some extra brightness to balance the
TV effect black lines.
=================================================*/
.container {
display: grid;
place-items: center;
filter: brightness(1.5);
}
/*=================================================
Our canvas will have a beautiful background.
We use grid properties to center it.
=================================================*/
.screen {
background: linear-gradient(67deg, #000 0%,#203 67%, #000 100%);
grid-row: 1;
grid-column: 1;
width: 100vmin;
height: 100vmin;
position: relative;
z-index: 0;
}
/*=================================================
The user interface will be positioned on top of
the canvas screen. to achive it we will use
the same row and column in our grid layout.
It will also allow us to easily position our
ship and mobile user interface.
To have a better understanding of the CSS stacking
context, take a look at this link:
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context.
We prevent text selection with "user-select".
=================================================*/
.ui {
grid-row: 1;
grid-column: 1;
display: grid;
user-select: none;
width: 100vw;
height: 100svh;
position: relative;
zoom: 1;
}
/*=================================================
Our github link will be white, always on the top
left and with no underline decoration.
=================================================*/
.ui a {
color: white;
position: absolute;
font-size: 4vmin;
margin: 5px;
padding: 1vmin;
text-decoration: none;
}
/*=================================================
We are going to use the "display: grid" again to
keep our sliders in place.
=================================================*/
.ui .shipMenu {
display: grid;
place-content: center;
}
/*=================================================
Our text style will be applied to all our title,
labels and buttons. We add a white color and some
text shadow to make it shinier!
Let's also align their text to the center.
=================================================*/
.ui h1,
.ui label,
.ui button {
color: white;
text-shadow: 0 0 5vmin white, 0 0 8vmin white;
text-align: center;
}
/*=================================================
Our game title font size and margin dimensions.
=================================================*/
.ui h1 {
font-size: 10vmin;
margin: 0 0 4vmin;
}
/*=================================================
Now we configure our label texts.
Setting "display: block" will assure it will take
the full rown and push down the next element.
Learn a but more about the display property here:
https://www.w3schools.com/cssref/pr_class_display.php
=================================================*/
.ui label {
font-size: 3.5vmin;
margin-bottom: 0.5vmin;
display: block;
}
/*=================================================
Let's make the mouse cursor transform into a pretty
hand when interacting with our sliders and buttons.
=================================================*/
.ui input,
.ui button {
cursor: pointer;
}
/*=================================================
Let's make our sliders dimensions more responsive.
Notice that we use (%) unit instead of "vw".
With percentages the value will be realtive to the
parent element instead of the full window length.
We also use max-width to prevent big ugly sliders
on super wide screens.
=================================================*/
.ui input {
display: block;
height: 4vmin;
margin: 0 0 3vmin;
width: 100%;
max-width: 100vmin;
}
/*=================================================
Our button font size will be a little bigger than
our labels. And it also needs some extra padding
to make easy to hit them with your fingers.
Let's also make the background animated when the
mouse is over with the transition property.
And put a nice round border around it.
=================================================*/
.ui button {
font-size: 4vmin;
padding: 3vmin;
border: solid 2px white;
border-radius: 2vmin;
background: #100010;
transition: background 0.2s;
}
/*=================================================
With the ":hover" pseudo selector we can add a
lighter background when the button is focused or
the mouse is over our button.
=================================================*/
.ui button:hover,
.ui button:focus,
.ui button:disabled {
background: #213;
}
/*=================================================
Always be careful while changing the focus style
and be sure not to break any accessibility rules
https://www.w3.org/WAI/WCAG21/Techniques/
=================================================*/
*:focus {
outline: 5px solid white;
}
/*=================================================
We add an underline effect to the first letter of
our buttons to hint their keyboard shotcuts with
the ":first-letter" pseudo selector.
Read more about pseudo selectors here:
https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
=================================================*/
.ui button:first-letter {
text-decoration:underline;
}
/*=================================================
And we make our disabled buttons look a bit less
interactive.
=================================================*/
.ui button:disabled {
opacity: 0.2;
cursor: default;
}
.ui .highScores {
position: absolute;
top: 0;
right: 0;
}
.ui .highScores label {
font-size: 3vmin;
}
/*=================================================
Let's use grid again to to keep mobile buttons
close to the fingers.
=================================================*/
.ui .mobileControls {
display: grid;
grid-auto-flow: column;
grid-template-columns: repeat(3, 1fr);
margin: 0 2vmin;
align-items: end;
column-gap: 2vw;
justify-items: center;
height: 90svh;
}
/*=================================================
Let's change the mobile buttons padding and margin
in order for them to properly fit the screen.
=================================================*/
.ui .mobileControls button {
margin: 2vmin 0 0;
}
/*=================================================
Now some CSS magic to select all the direct
children of the mobileMenu.
=================================================*/
.ui .mobileControls > * {
max-width: 200px;
width: 30vw;
}
/*=================================================
We need to assure the move button will always stay
on top and have the same width as the left and
right buttons below combined.
=================================================*/
.ui button[name="shoot"] {
display: block;
width: 100%;
}
/*=================================================
And let's place the left and right buttons side
by side with a small gap between.
=================================================*/
.ui .turnControls {
display: grid;
grid-auto-flow: column;
grid-gap: 2vmin;
}
/*=================================================
And we can remove the single character buttons
first letter underline text decoration.
=================================================*/
.ui .turnControls button:first-letter {
text-decoration: none;
}
/*=================================================
And finally we will need to hide our mobile menu,
to achieve that lets set display to none.
=================================================*/
.ui .hidden {
display: none;
}
/*=================================================
We want the TV effect to be drawn on top of our
canvas and user interface. We don't want it to
block the user from clicking the interface so we
set it to have no pointer events.
=================================================*/
.screenEffect {
pointer-events: none;
width: 100vw;
height: 100svh;
position: absolute;
top: 0;
left: 0;
z-index: 3;
}
/*=================================================
Now that we have the style configured, let's dive
into our world, open "P03-world-astedoids.js"
=================================================*/