Skip to content

Commit 9594a72

Browse files
committed
Day 3.
1 parent 1fd9d08 commit 9594a72

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

03 - CSS Variables/index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Scoped CSS Variables and JS</title>
6+
<link rel="stylesheet" href="style.css">
7+
</head>
8+
<body>
9+
10+
<h2>Update CSS Variables with <span class="hl">JS</span></h2>
11+
12+
<div class="controls">
13+
<label for="spacing">Spacing:</label>
14+
<input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
15+
16+
<label for="blur">Blur:</label>
17+
<input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
18+
19+
<label for="base">Base Color</label>
20+
<input id="base" type="color" name="base" value="#ffc600">
21+
</div>
22+
23+
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
24+
25+
<script>
26+
const body = document.body;
27+
28+
function updateVariable() {
29+
body.style.setProperty( `--${this.getAttribute( 'name' )}`, this.value + ( this.dataset.sizing || '' ) );
30+
}
31+
32+
document.querySelectorAll( '.controls input' ).forEach( ( el ) => {
33+
updateVariable.call( el );
34+
el.addEventListener( 'input', updateVariable );
35+
} );
36+
</script>
37+
38+
</body>
39+
</html>

03 - CSS Variables/style.css

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

0 commit comments

Comments
 (0)