-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
242 lines (189 loc) · 4.95 KB
/
index.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
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
<!doctype html>
<html>
<head>
<style>
.vertically-centered,
.aspect-ratio {
font-size:0;
position:relative;
display:block;
text-align:center;
}
.vertically-centered:before,
.aspect-ratio:before {
content:"";
width:0;
display:inline-block;
vertical-align:middle;
}
.vertically-centered:before {
height:100%;
}
.aspect-ratio:before {
height:0;
/* defaults to 4/3 */
padding-top:75%;
}
.aspect-ratio--golden:before {
padding-top:61.8%;
}
.aspect-ratio--widescreen:before {
/* ratio 16:9 */
padding-top: 56.25%;
}
.aspect-ratio--square:before {
/* ratio 1:1 */
padding-top: 100%;
}
.vertically-centered__content,
.aspect-ratio__content {
position:relative;
z-index:2;
display:inline-block;
/* because the content is being centered horizontally, it is easier to use width rather than padding and margins for spacing. maybe */
width:90%;
/* undo the settings on the parent (if necessary) */
text-align:left;
font-size:10px;
font-size:1rem;
padding:15px 0;
}
.vertically-centered__content {
vertical-align:middle;
}
.aspect-ratio__content {
vertical-align:top;
}
.vertically-centered--underlay:after,
.aspect-ratio--underlay:after {
content:"";
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
background:rgba(0,0,0,0.3);
}
.vertically-centered--hover:after,
.aspect-ratio--hover:after {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
-moz-transition:all 0.5s;
-webkit-transition:all 0.5s;
-ms-transition:all 0.5s;
transition:all 0.5s;
border: 0 solid #9A806B;
}
.vertically-centered--hover:hover,
.aspect-ratio--hover:hover {
/* an empty hover is needed for all version of IE to make :hover:after work */
/* the zoom is needed for IE 8 */
zoom:1;
}
.vertically-centered--hover:hover:after,
.aspect-ratio--hover:hover:after {
background: rgba(0, 0, 0, 0.8);
border: 10px solid #9A806B;
}
.vertically-centered__cover,
.aspect-ratio__cover {
/* cover is will be under content if both present */
position:absolute;
z-index:1;
top:0;
left:0;
width:100%;
height:100%;
}
p {
font-size:30px;
font-size:3rem;
color:white;
text-align:center;
margin:0;
padding:0;
}
/* non specific */
html {
font-size:62.5%;
}
body {
padding-bottom:400px;
}
.horizontal-half {
width:50%;
}
.some-sized-panel {
height:300px;
background:#f00;
width:48%;
display:inline-block;
}
.some-sized-panel:nth-child(even) {
background:#0fa;
}
hr {
margin:20px 0;
}
</style>
<!--[if lte IE 8]>
<style>
.vertically-centered--underlay:after,
.aspect-ratio--underlay:after {
background:url('lightbg.png');
}
.vertically-centered--hover:hover:after,
.aspect-ratio--hover:hover:after {
background:url('darkbg.png');
}
</style>
<!--<![endif]-->
<script>
function addContent() {
// very specific function for adding content
var el = Array.prototype.slice.call(document.getElementsByClassName("vertically-centered__content"),0).pop();
el.innerHTML += '<p>More content!</p>';
}
</script>
</head>
<body>
<div class="vertically-centered some-sized-panel">
<div class="vertically-centered__content">
<p>Vertical text</p>
<p>Arbitrary fixed height</p>
<p>Can be problem if content is bigger than height</p>
<p>I think every vertical centering has this problem. Maybe not the table-cell one, but it has issues of it's own</p>
</div>
</div>
<div class="vertically-centered some-sized-panel">
<div class="vertically-centered__content">
<p><-- I'm with stupid</p>
</div>
</div>
<hr style="clear:both;overflow:hidden;"/>
<div class="horizontal-half aspect-ratio aspect-ratio--widescreen" style="background: url('http://lorempixel.com/900/500/food/1/');background-size:cover;"></div>
<hr/>
<div class="horizontal-half aspect-ratio aspect-ratio--widescreen" style="background: url('http://lorempixel.com/900/500/food/2/');background-size:cover;">
<div class="vertically-centered__content">
<p>line of centered content</p>
<p>can't read it properly</p>
</div>
</div>
<hr/>
<div class="horizontal-half aspect-ratio aspect-ratio--widescreen aspect-ratio--underlay" style="background: url('http://lorempixel.com/900/500/food/3/');background-size:cover;">
<div class="vertically-centered__content">
<p>line of centered content</p>
<p>Using widescreen ratio</p>
<p>Add underlay to help read it a bit better?</p>
</div>
</div>
<hr/>
<button onclick="addContent();">Add more content</button>
<a href="#biscuits" class="horizontal-half aspect-ratio aspect-ratio--golden aspect-ratio--underlay aspect-ratio--hover" style="background: url('http://lorempixel.com/900/500/food/4/');background-size:cover;">
<div class="vertically-centered__content">
<p>line of centered content. I am a bit larger so I should go over two lines</p>
<p>Has underlay and hover effects with golden ratio</p>
</div>
</a>
</body>