Skip to content

Commit b4b7d03

Browse files
committed
[css-sizing-4] Add aspect-ratio examples
1 parent eaccbc4 commit b4b7d03

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

css-sizing-4/Overview.bs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,59 @@ Intrinsic Aspect Ratios: the 'aspect-ratio' property</h3>
103103

104104
ISSUE: Clarify interaction with intrinsic size keywords like ''width/min-content'' etc.
105105

106-
ISSUE: Add examples
106+
<div class="example">
107+
This example sets each item in the grid to render as a square,
108+
determining the number of items and their widths by the available space.
109+
110+
<xmp highlight="html">
111+
<ul>
112+
<li>
113+
<li>
114+
<li>
115+
<li>
116+
</ul>
117+
</xmp>
118+
<pre highlight="css">
119+
ul {
120+
display: grid;
121+
grid-template-columns: repeat(auto-fill, minmax(12em, 1fr));
122+
}
123+
li {
124+
aspect-ratio: 1/1;
125+
overflow: auto;
126+
}
127+
</pre>
128+
</div>
129+
130+
<div class="example">
131+
This example uses the <{iframe}> element’s
132+
<code>width</code> and <code>height</code> attributes
133+
to set the 'aspect-ratio' property,
134+
giving the iframe an aspect ratio to use for sizing
135+
so that it behaves exactly like an image with that aspect ratio.
136+
<!-- https://twitter.com/ausi/status/1053013616239288320 -->
137+
<pre highlight="html">
138+
&lt;iframe
139+
src="https://www.youtube.com/embed/0Gr1XSyxZy0"
140+
width=560
141+
height=315>
142+
</pre>
143+
<pre highlight="css">
144+
@supports (aspect-ratio: attr(width px) / 1) {
145+
iframe {
146+
aspect-ratio: attr(width px) / attr(height px);
147+
width: 100%;
148+
height: auto;
149+
}
150+
}
151+
</pre>
152+
ISSUE: Can we just slip this 'aspect-ratio' rule
153+
into the UA default style sheet for images,
154+
so that they have an aspect ratio while they load?
155+
This would avoid the need for extra reflows after loading.
156+
</div>
107157

108-
<h3 id="min/max-ratio">
158+
<h3 id="from-ratio">
109159
Aspect Ratio Limits Option A: the ''from-ratio''</h3>
110160

111161
<pre class="partial propdef">
@@ -149,7 +199,7 @@ Aspect Ratio Limits Option A: the ''from-ratio''</h3>
149199
</pre>
150200
</div>
151201

152-
<h3 id="min/max-ratio">
202+
<h3 id="ar-width-height">
153203
Aspect Ratio Limits Option B: the ''ar'' unit</h3>
154204

155205
<pre class="partial propdef">
@@ -413,7 +463,7 @@ Contain-fit Sizing: stretching while maintaining an aspect ratio</h3>
413463
Contain-fit sizing essentially applies stretch-fit sizing,
414464
but reduces the size of the box in one axis
415465
to maintain the box’s intrinsic aspect ratio,
416-
similar to the ''contain'' keyword of the 'object-fit' and 'background-size' properties.
466+
similar to the ''object-fit/contain'' keyword of the 'object-fit' and 'background-size' properties.
417467

418468
First, a target rectangle is determined:
419469

0 commit comments

Comments
 (0)