Skip to content

Commit b379d16

Browse files
committed
finished challenge wesbos#3
1 parent 61f4e79 commit b379d16

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

03 - CSS Variables/index-START.html

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Scoped CSS Variables and JS</title>
6+
<link rel="stylesheet" href="style.css">
67
</head>
78
<body>
8-
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
9+
<h2>Update CSS Variables with <span class='h1'>JS</span></h2>
910

1011
<div class="controls">
1112
<label for="spacing">Spacing:</label>
@@ -20,32 +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-
background: #193549;
32-
color: white;
33-
font-family: 'helvetica neue', sans-serif;
34-
font-weight: 100;
35-
font-size: 50px;
36-
}
37-
38-
.controls {
39-
margin-bottom: 50px;
40-
}
41-
42-
input {
43-
width: 100px;
44-
}
45-
</style>
46-
47-
<script>
48-
</script>
25+
<script type="text/javascript" src="script.js"></script>
4926

5027
</body>
5128
</html>

03 - CSS Variables/script.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/style.css

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

0 commit comments

Comments
 (0)