-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
185 lines (161 loc) · 7.18 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
<!DOCTYPE html>
<html>
<head>
<title>Object fit cover</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<script src="objectfitcover.min.js"></script>
<link rel="stylesheet" href="objectfitcover.min.css" />
<style>
.object-fit-container-example-1 {
width: 100%;
height: 300px;
}
.object-fit-container-example-2 {
width: 100%;
height: 300px;
}
.object-fit-container-example-3 {
width: 100%;
height: 300px;
}
@media (max-width: 991px) {
.object-fit-container-example-3 {
height: 600px;
}
}
</style>
<link rel="stylesheet" href="bootstrap.min.css" />
</head>
<body>
<div class="ui container">
<div class="jumbotron">
<h1 class="">Responsive background image cover with the <img> tag</h1>
</div>
<div>
<h1 id="examples">Examples</h1>
<h3>Image without responsive behaviour</h3>
<div class="panel panel-default">
<div class="panel-body">
<pre>
.object-fit-container-example-1 {
width: 100%;
height: 300px;
}
</pre>
<pre>
<div class="object-fit-container cover object-fit-container-example-1">
<img src="example-images/[email protected]" alt="Example image" />
</div>
</pre>
<div class="object-fit-container cover object-fit-container-example-1">
<img src="example-images/[email protected]"
alt="Example 1" />
</div>
</div>
</div>
<h3>Image with responsive behaviour (srcset attribute)</h3>
<p>
Want to know more about using srcset or the picture element? Read about it on <a href="https://jakearchibald.com/2015/anatomy-of-responsive-images/">Jake Archibalds blog</a>
</p>
<div class="panel panel-default">
<div class="panel-body">
<pre>
.object-fit-container-example-2 {
width: 100%;
height: 300px;
}
</pre>
<pre>
<div class="object-fit-container cover object-fit-container-example-2">
<img src="example-images/[email protected]"
srcset="example-images/[email protected] 2400w,
example-images/[email protected] 1200w,
example-images/[email protected] 800w,
example-images/[email protected] 400w"
sizes="(min-width: 1200px) 1170px,
(min-width: 992px) 970px,
(min-width: 768px) 750px,
100vw"
alt="Example 2" />
</div>
</pre>
<div class="object-fit-container cover object-fit-container-example-2">
<img src="example-images/[email protected]"
srcset="example-images/[email protected] 2400w,
example-images/[email protected] 1200w,
example-images/[email protected] 800w,
example-images/[email protected] 400w"
sizes="(min-width: 1200px) 1170px,
(min-width: 992px) 970px,
(min-width: 768px) 750px,
100vw"
alt="Example 2" />
</div>
<p>
Note: You only will see a changing src image when starting with a small viewport width. The browsers only downloads larger images when having cached versions of the same image.
</p>
</div>
</div>
<h3>Image with responsive behaviour (picture-tag)</h3>
<p>
Want to know more about using srcset or the picture element? Read about it on <a href="https://jakearchibald.com/2015/anatomy-of-responsive-images/">Jake Archibald's blog</a>
</p>
<div class="panel panel-default">
<div class="panel-body">
<pre>
.object-fit-container-example-3 {
width: 100%;
height: 300px;
}
@media (max-width: 991px) {
.object-fit-container-example-3 {
height: 600px;
}
}
</pre>
<pre>
<div class="object-fit-container cover object-fit-container-example-3">
<picture>
<!--[if IE 9]><video style="display: none;"><![endif]-->
// the portrait picture
<source media="(max-width: 991px)"
srcset="example-images/[email protected] 800w,
example-images/[email protected] 400w"
sizes="(min-width: 768px) 720px, 100vw">
<!--[if IE 9]></video><![endif]-->
// the landscape picture
<img srcset="example-images/[email protected] 2400w,
example-images/[email protected] 1200w"
sizes="(min-width: 1200px) 1140px, (min-width: 992px) 940px"
alt="Example 3" />
</picture>
</div>
</pre>
<p>
Note: More about the IE9 fix on the <a href="http://scottjehl.github.io/picturefill/#ie9">Picturefill website</a>.
</p>
<div class="object-fit-container cover object-fit-container-example-3">
<picture>
<!--[if IE 9]><video style="display: none;"><![endif]-->
<source media="(max-width: 991px)"
srcset="example-images/[email protected] 800w,
example-images/[email protected] 400w"
sizes="(min-width: 768px) 720px, 100vw">
<!--[if IE 9]></video><![endif]-->
<img
srcset="example-images/[email protected] 2400w,
example-images/[email protected] 1200w"
sizes="(min-width: 1200px) 1140px, (min-width: 992px) 940px"
alt="Example 3" />
</picture>
</div>
<p>
Note: You only will see a changing src image when starting with a small viewport width. When the browsers already has downloaded a larger image, then the smaller isn't downloaded anymore.
</p>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/picturefill/3.0.2/picturefill.min.js" async></script>
</body>
</html>