You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,4 +6,6 @@ The "counter-style-demo" directory contains a demo for the [@counter-style docum
6
6
7
7
The "editable-examples" directory contains CSS examples that are intended to be embedded in MDN pages as live editable samples.
8
8
9
+
The "object-fit-basics" directory contains a simple page demonstrating typical usage of different <code>object-fit</code> and <code>object-position</code> values. [Run example live](http://mdn.github.io/css-examples/object-fit-basics/).
10
+
9
11
The "object-fit-gallery" directory contains a fun image gallery that uses <code>object-fit</code> to display the images more nicely, both in thumbnail and full size view. [Run the example live](http://mdn.github.io/css-examples/object-fit-gallery/).
<p>This page illustrates different object-fit settings. It is part of the <ahref="http://hacks.mozilla.org/2015/01/exploring-object-fit/">Exploring object-fit</a> Mozilla Hacks post. For the following examples to work, you'll need to be using a fairly new browser — Firefox 36+, Chrome 31+, Opera 26+ or Safari 8+. The latter supports <code>object-fit</code>, but not <code>object-position</code>.</p>
21
+
22
+
<h2id="contain">object-fit: contain</h2>
23
+
24
+
<p>with <code>object-fit: contain</code>, the image is letterboxed inside the image element, retaining its aspect ratio.</p>
25
+
26
+
<imgsrc="flowers.jpg" class="contain" alt="with object-fit contain, the image is trapped inside the image element, retaining aspect ratio.">
27
+
28
+
<h2id="cover">object-fit: cover</h2>
29
+
30
+
<p>with <code>object-fit: cover</code>, the image completely covers the image element — it is shown completely along the shortest dimension, and will be cut off in the other direction.</p>
31
+
32
+
<imgsrc="flowers.jpg" class="cover" alt="with object-fit cover, the image completely covers the image element and is cropped along the longest dimension">
33
+
34
+
<h2id="fill">object-fit: fill</h2>
35
+
36
+
<p><code>Object-fill: fill</code> can override a video’s intrinsic aspect ratio, forcing it to completely fill the <code><video></code> element. This is good for correcting videos with broken aspect ratios.</p>
37
+
38
+
<videocontrols="controls" src="windowsill.webm"
39
+
width="426" height="240" class="fill">
40
+
<p>HTML5 video not supported?</p>
41
+
</video>
42
+
43
+
<p><button>Turn object-fit: fill off</button></p>
44
+
45
+
<h2id="none">object-fit: none</h2>
46
+
47
+
<p>Combining <code>object-fit</code> and <code>object-position</code> with CSS transitions can lead to some pretty interesting effects for image or video galleries.</p>
48
+
49
+
<imgsrc="flowers.jpg" class="none" alt="when hovered over the image element expands to reveal more of the image" tabindex="0">
50
+
51
+
<h2id="position">object-position</h2>
52
+
53
+
<p>The three images below have <code>object-fit: cover</code>, and three different <code>object-position</code> values set on them: <code>0 0</code>, <code>bottom</code>, and <code>100px 100px</code> respectively.</p>
54
+
55
+
<imgsrc="flowers.jpg" class="objpos pos1" alt="when hovered over the image element expands to reveal more of the image">
56
+
57
+
<imgsrc="flowers.jpg" class="objpos pos2" alt="when hovered over the image element expands to reveal more of the image">
58
+
59
+
<imgsrc="flowers.jpg" class="objpos pos3" alt="when hovered over the image element expands to reveal more of the image">
0 commit comments