This repository was archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtechnique2.html
110 lines (82 loc) · 2.63 KB
/
technique2.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Frosted Glass</title>
<link rel="stylesheet" href="./technique2.css">
</head>
<body>
<div class="wrap">
<h1>Frosted Glass Techniques</h1>
<p>because bugs.</p>
<hr/>
<div id="nav">
<ul>
<li>
<a href="./index.html">Technique #1</a>
</li>
<li>
<a href="./technique2.html">Technique #2</a>
</li>
</ul>
</div>
<hr/>
<h2>Technique #2</h2>
<blockquote>
This gets weird on Chrome.<br/>
When you adjust the <strong>height</strong> of the window, the div's<br/>
background will not adjust with you.<br/>
But adjusting the <strong>width</strong> works fine..
</blockquote>
<p>This technique is all about toying with the ::before selector of the div.</p>
<p>Take a regular background image</p>
<p><img src="back.jpg" width="160px" height="90px;"></p>
<p>and set the body's background to the image.</p>
<pre>
body {
background: url('original_background.jpg') no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
}</pre>
<p>Here's where it gets freaky.</p>
<p>Create empty content in the div's ::before then set its z-index to -1.</p>
<pre>
.my_div::before {
content: ' ';
z-index: -1; /* places the blurred mess behind the div's content */
}</pre>
<p>Expand this ::before pseudo-element to fit the size of the div. Then filter it.</p>
<pre>
.my_div::before {
content: ' ';
z-index: -1; /* places the blurred mess behind the div's content */
position: absolute; /* expand */
width: 100%;
height: 100%;
filter: blur(3px); /* filter */
-moz-filter: blur(3px);
-webkit-filter: blur(3px);
}</pre>
<p>What you'll notice is that the top & left edges of this div won't be blurred.</p>
<p>This is because filter affects the entire pseudo-element within its parent as seen below.</p>
<img src="./example1.png" alt="">
<p>The solution to this issue is to expand the pseudo-element past its parent.</p>
<p>That way we get a clean blur all around.</p>
<img src="./example2.png" alt="">
<pre>
.my_div::before {
content: ' ';
z-index: -1; /* places the blurred mess behind the div's content */
position: absolute; /* expand */
<b>width: 110%;
height: 110%;</b> /* expand past its parent's boundaries */
<b>top: -15px;
left: -15px;</b> /* position it to fill the top & left edges */
filter: blur(3px); /* filter */
-moz-filter: blur(3px);
-webkit-filter: blur(3px);
}</pre>
</div>
</body>
</html>