Visitar URL original
css variables exercise complete · wesbos/JavaScript30@c3eac16 · GitHub
Skip to content

Commit c3eac16

Browse files
committed
css variables exercise complete
1 parent 5df63c0 commit c3eac16

3 files changed

Lines changed: 47 additions & 28 deletions

File tree

‎03 - CSS Variables/index-START.html‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Scoped CSS Variables and JS</title>
6+
<link rel='stylesheet' href='styles/main.css'>
67
</head>
78
<body>
89
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
@@ -20,35 +21,8 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2021

2122
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
2223

23-
<style>
2424

25-
/*
26-
misc styles, nothing to do with CSS variables
27-
*/
28-
29-
body {
30-
text-align: center;
31-
}
32-
33-
body {
34-
background: #193549;
35-
color: white;
36-
font-family: 'helvetica neue', sans-serif;
37-
font-weight: 100;
38-
font-size: 50px;
39-
}
40-
41-
.controls {
42-
margin-bottom: 50px;
43-
}
44-
45-
input {
46-
width:100px;
47-
}
48-
</style>
49-
50-
<script>
51-
</script>
25+
<script src='js/app.js'></script>
5226

5327
</body>
5428
</html>

‎03 - CSS Variables/js/app.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const inputs = document.querySelectorAll('.controls input');
2+
3+
function handleUpdate() {
4+
const suffix = this.dataset.sizing || '';
5+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
6+
}
7+
8+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
9+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));

‎03 - CSS Variables/styles/main.css‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
:root {
3+
--base: #ffc600;
4+
--spacing: 10px;
5+
--blur: 10px;
6+
}
7+
8+
img {
9+
padding: var(--spacing);
10+
background: var(--base);
11+
filter: blur(var(--blur));
12+
}
13+
14+
.hl {
15+
color: var(--base);
16+
}
17+
18+
body {
19+
text-align: center;
20+
}
21+
22+
body {
23+
background: #193549;
24+
color: white;
25+
font-family: 'helvetica neue', sans-serif;
26+
font-weight: 100;
27+
font-size: 50px;
28+
}
29+
30+
.controls {
31+
margin-bottom: 50px;
32+
}
33+
34+
input {
35+
width:100px;
36+
}

0 commit comments

Comments
 (0)