aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/svg/attribute/preserveaspectratio/index.html
blob: ee9351ad58aba168d45a8defe3200ceb24a1255d (plain)
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
---
title: preserveAspectRatio
slug: Web/SVG/Attribute/preserveAspectRatio
translation_of: Web/SVG/Attribute/preserveAspectRatio
---
<div>{{SVGRef}}</div>

<p>O atributo <code><strong>preserveAspectRatio</strong></code> indica como um elemento com uma viewBox, fornecendo uma determinada proporção deve se ajustar a uma viewport com uma proporção diferente.</p>

<p>Because the aspect ratio of an SVG image is defined by the {{SVGAttr('viewBox')}} attribute, if this attribute isn't set, the <code>preserveAspectRatio</code> attribute has no effect (<em>with one exception, the {{SVGElement('image')}} element, as described below</em>).</p>

<h2 id="Example">Example</h2>

<pre class="brush: html">&lt;svg viewBox="-1 -1 162 92" xmlns="http://www.w3.org/2000/svg"&gt;
  &lt;defs&gt;
     &lt;path id="smiley" d="M50,10 A40,40,1,1,1,50,90 A40,40,1,1,1,50,10 M30,40 Q36,35,42,40 M58,40 Q64,35,70,40 M30,60 Q50,75,70,60 Q50,75,30,60" /&gt;
  &lt;/defs&gt;

  &lt;!-- (width&gt;height) meet --&gt;
  &lt;svg preserveAspectRatio="xMidYMid meet"  x="0"   y="0"  viewBox="0 0 100 100" width="20"  height="10"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMinYMid meet"  x="25"  y="0"  viewBox="0 0 100 100" width="20"  height="10"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMaxYMid meet"  x="50"  y="0"  viewBox="0 0 100 100" width="20"  height="10"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;

  &lt;!-- (width&gt;height) slice --&gt;
  &lt;svg preserveAspectRatio="xMidYMin slice" x="0"   y="15" viewBox="0 0 100 100" width="20"  height="10"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMidYMid slice" x="25"  y="15" viewBox="0 0 100 100" width="20"  height="10"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMidYMax slice" x="50"  y="15" viewBox="0 0 100 100" width="20"  height="10"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;

  &lt;!-- (width&lt;height) meet --&gt;
  &lt;svg preserveAspectRatio="xMidYMin meet"  x="75"  y="0"  viewBox="0 0 100 100" width="10"  height="25"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMidYMid meet"  x="90"  y="0"  viewBox="0 0 100 100" width="10"  height="25"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMidYMax meet"  x="105" y="0"  viewBox="0 0 100 100" width="10"  height="25"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;

  &lt;!-- (width&lt;height) slice --&gt;
  &lt;svg preserveAspectRatio="xMinYMid slice" x="120" y="0"  viewBox="0 0 100 100" width="10"  height="25"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMidYMid slice" x="135" y="0"  viewBox="0 0 100 100" width="10"  height="25"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
  &lt;svg preserveAspectRatio="xMaxYMid slice" x="150" y="0"  viewBox="0 0 100 100" width="10"  height="25"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;

  &lt;!-- none --&gt;
  &lt;svg preserveAspectRatio="none"           x="0"   y="30" viewBox="0 0 100 100" width="160" height="60"&gt;&lt;use href="#smiley" /&gt;&lt;/svg&gt;
&lt;/svg&gt;</pre>

<div class="hidden">
<h6 id="topExample">topExample</h6>

<pre class="brush: css">html,body,svg { height:100% }
</pre>

<pre class="brush: html">&lt;svg viewBox="-1 -1 162 92" xmlns="http://www.w3.org/2000/svg"&gt;
  &lt;defs&gt;
     &lt;path id="smiley" d="M50,10 A40,40,1,1,1,50,90 A40,40,1,1,1,50,10 M30,40 Q36,35,42,40 M58,40 Q64,35,70,40 M30,60 Q50,75,70,60 Q50,75,30,60" /&gt;
  &lt;/defs&gt;

  &lt;!-- (width&gt;height) meet --&gt;
  &lt;rect x="0" y="0" width="20" height="10"&gt;
    &lt;title&gt;xMidYMid meet&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="20" height="10"
       preserveAspectRatio="xMidYMid meet" x="0" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="25" y="0" width="20" height="10"&gt;
    &lt;title&gt;xMinYMid meet&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="20" height="10"
       preserveAspectRatio="xMinYMid meet" x="25" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="50" y="0" width="20" height="10"&gt;
    &lt;title&gt;xMaxYMid meet&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="20" height="10"
       preserveAspectRatio="xMaxYMid meet" x="50" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;!-- (width&gt;height) slice --&gt;
  &lt;rect x="0" y="15" width="20" height="10"&gt;
    &lt;title&gt;xMidYMin slice&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="20" height="10"
       preserveAspectRatio="xMidYMin slice" x="0" y="15"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="25" y="15" width="20" height="10"&gt;
    &lt;title&gt;xMidYMid slice&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="20" height="10"
       preserveAspectRatio="xMidYMid slice" x="25" y="15"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="50" y="15" width="20" height="10"&gt;
    &lt;title&gt;xMidYMax slice&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="20" height="10"
       preserveAspectRatio="xMidYMax slice" x="50" y="15"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;!-- (width&lt;height) meet --&gt;
  &lt;rect x="75" y="0" width="10" height="25"&gt;
    &lt;title&gt;xMidYMin meet&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="10" height="25"
       preserveAspectRatio="xMidYMin meet" x="75" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="90" y="0" width="10" height="25"&gt;
    &lt;title&gt;xMidYMid meet&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="10" height="25"
       preserveAspectRatio="xMidYMid meet" x="90" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="105" y="0" width="10" height="25"&gt;
    &lt;title&gt;xMidYMax meet&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="10" height="25"
       preserveAspectRatio="xMidYMax meet" x="105" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;!-- (width&lt;height) slice --&gt;
  &lt;rect x="120" y="0" width="10" height="25"&gt;
    &lt;title&gt;xMinYMid slice&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="10" height="25"
       preserveAspectRatio="xMinYMid slice" x="120" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="135" y="0" width="10" height="25"&gt;
    &lt;title&gt;xMidYMid slice&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="10" height="25"
       preserveAspectRatio="xMidYMid slice" x="135" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;rect x="150" y="0" width="10" height="25"&gt;
    &lt;title&gt;xMaxYMid slice&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="10" height="25"
       preserveAspectRatio="xMaxYMid slice" x="150" y="0"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;

  &lt;!-- none --&gt;
  &lt;rect x="0" y="30" width="160" height="60"&gt;
    &lt;title&gt;none&lt;/title&gt;
  &lt;/rect&gt;
  &lt;svg viewBox="0 0 100 100" width="160" height="60"
       preserveAspectRatio="none" x="0" y="30"&gt;
    &lt;use href="#smiley" /&gt;
  &lt;/svg&gt;
&lt;/svg&gt;</pre>

<pre class="brush: css">path {
  fill: yellow;
  stroke: black;
  stroke-width: 8px;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

rect:hover, rect:active {
  outline: 1px solid red;
}</pre>
</div>

<p>{{EmbedLiveSample('topExample', '100%', 200)}}</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">preserveAspectRatio="&lt;align&gt; [&lt;meetOrSlice&gt;]"</pre>

<p>Its value is made of one or two keywords: A required alignment value and an optional "meet or slice" reference as described below:</p>

<dl>
 <dt>Alignment value</dt>
 <dd>The alignment value indicates whether to force uniform scaling and, if so, the alignment method to use in case the aspect ratio of the {{ SVGAttr("viewBox") }} doesn't match the aspect ratio of the viewport. The alignment value must be one of the following keywords:
 <ul>
  <li><strong>none</strong><br>
   Do not force uniform scaling. Scale the graphic content of the given element non-uniformly if necessary such that the element's bounding box exactly matches the viewport rectangle. <em>Note that if </em><code>&lt;align&gt;</code><em> is </em><code>none</code><em>, then the optional </em><code>&lt;meetOrSlice&gt;</code><em> value is ignored</em>.</li>
  <li><strong>xMinYMin</strong> - Force uniform scaling.<br>
   Align the <code>&lt;min-x&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the smallest X value of the viewport.<br>
   Align the <code>&lt;min-y&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the smallest Y value of the viewport.</li>
  <li><strong>xMidYMin</strong> - Force uniform scaling.<br>
   Align the midpoint X value of the element's {{ SVGAttr("viewBox") }} with the midpoint X value of the viewport.<br>
   Align the <code>&lt;min-y&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the smallest Y value of the viewport.</li>
  <li><strong>xMaxYMin</strong> - Force uniform scaling.<br>
   Align the <code>&lt;min-x&gt;+&lt;width&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the maximum X value of the viewport.<br>
   Align the <code>&lt;min-y&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the smallest Y value of the viewport.</li>
  <li><strong>xMinYMid</strong> - Force uniform scaling.<br>
   Align the <code>&lt;min-x&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the smallest X value of the viewport.<br>
   Align the midpoint Y value of the element's {{ SVGAttr("viewBox") }} with the midpoint Y value of the viewport.</li>
  <li><strong>xMidYMid</strong> (the default) - Force uniform scaling.<br>
   Align the midpoint X value of the element's {{ SVGAttr("viewBox") }} with the midpoint X value of the viewport.<br>
   Align the midpoint Y value of the element's {{ SVGAttr("viewBox") }} with the midpoint Y value of the viewport.</li>
  <li><strong>xMaxYMid</strong> - Force uniform scaling.<br>
   Align the <code>&lt;min-x&gt;+&lt;width&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the maximum X value of the viewport.<br>
   Align the midpoint Y value of the element's {{ SVGAttr("viewBox") }} with the midpoint Y value of the viewport.</li>
  <li><strong>xMinYMax</strong> - Force uniform scaling.<br>
   Align the <code>&lt;min-x&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the smallest X value of the viewport.<br>
   Align the <code>&lt;min-y&gt;+&lt;height&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the maximum Y value of the viewport.</li>
  <li><strong>xMidYMax</strong> - Force uniform scaling.<br>
   Align the midpoint X value of the element's {{ SVGAttr("viewBox") }} with the midpoint X value of the viewport.<br>
   Align the <code>&lt;min-y&gt;+&lt;height&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the maximum Y value of the viewport.</li>
  <li><strong>xMaxYMax</strong> - Force uniform scaling.<br>
   Align the <code>&lt;min-x&gt;+&lt;width&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the maximum X value of the viewport.<br>
   Align the <code>&lt;min-y&gt;+&lt;height&gt;</code> of the element's {{ SVGAttr("viewBox") }} with the maximum Y value of the viewport.</li>
 </ul>
 </dd>
 <dt>Meet or slice reference</dt>
 <dd>The meet or slice reference is optional and, if provided, must be one of the following keywords:
 <ul>
  <li><strong>meet</strong> (<em>the default</em>) - Scale the graphic such that:
   <ul>
    <li>aspect ratio is preserved</li>
    <li>the entire {{ SVGAttr("viewBox") }} is visible within the viewport</li>
    <li>the {{ SVGAttr("viewBox") }} is scaled up as much as possible, while still meeting the other criteria</li>
   </ul>
   In this case, if the aspect ratio of the graphic does not match the viewport, some of the viewport will extend beyond the bounds of the {{ SVGAttr("viewBox") }} (i.e., the area into which the {{ SVGAttr("viewBox") }} will draw will be smaller than the viewport).</li>
  <li><strong>slice</strong> - Scale the graphic such that:
   <ul>
    <li>aspect ratio is preserved</li>
    <li>the entire viewport is covered by the {{ SVGAttr("viewBox") }}</li>
    <li>the {{ SVGAttr("viewBox") }} is scaled down as much as possible, while still meeting the other criteria</li>
   </ul>
   In this case, if the aspect ratio of the {{ SVGAttr("viewBox") }} does not match the viewport, some of the {{ SVGAttr("viewBox") }} will extend beyond the bounds of the viewport (i.e., the area into which the {{ SVGAttr("viewBox") }} will draw is larger than the viewport).</li>
 </ul>
 </dd>
</dl>

<h2 id="Elements">Elements</h2>

<p>Seven elements are using this attribute: {{SVGElement("svg")}}, {{SVGElement("symbol")}}, {{SVGElement("image")}}, {{SVGElement("feImage")}}, {{SVGElement("marker")}}, {{SVGElement("pattern")}}, and {{SVGElement("view")}}.</p>

<h3 id="feImage">feImage</h3>

<p>For {{SVGElement('feImage')}}, <code>preserveAspectRatio</code> defines how the referenced image should fit in the rectangle define by the <code>&lt;feImage&gt;</code> element.</p>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Value</th>
   <td><strong>&lt;align&gt; &lt;meetOrSlice&gt;?</strong></td>
  </tr>
  <tr>
   <th scope="row">Default value</th>
   <td><code>xMidYMid</code> <code>meet</code></td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h3 id="image">image</h3>

<p>For {{SVGElement('image')}}, <code>preserveAspectRatio</code> defines how the referenced image should fit in the rectangle define by the <code>&lt;image&gt;</code> element.</p>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Value</th>
   <td><strong>&lt;align&gt; &lt;meetOrSlice&gt;?</strong></td>
  </tr>
  <tr>
   <th scope="row">Default value</th>
   <td><code>xMidYMid</code> <code>meet</code></td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h3 id="marker">marker</h3>

<p>For {{SVGElement('marker')}}, <code>preserveAspectRatio</code> indicates if a uniform scaling must be performed to fit the element viewport.</p>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Value</th>
   <td><strong>&lt;align&gt; &lt;meetOrSlice&gt;?</strong></td>
  </tr>
  <tr>
   <th scope="row">Default value</th>
   <td><code>xMidYMid</code> <code>meet</code></td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h3 id="pattern">pattern</h3>

<p>For {{SVGElement('pattern')}}, <code>preserveAspectRatio</code> indicates if a uniform scaling must be performed to fit the element viewport.</p>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Value</th>
   <td><strong>&lt;align&gt; &lt;meetOrSlice&gt;?</strong></td>
  </tr>
  <tr>
   <th scope="row">Default value</th>
   <td><code>xMidYMid</code> <code>meet</code></td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h3 id="svg">svg</h3>

<p>For {{SVGElement('svg')}}, <code>preserveAspectRatio</code> indicates if a uniform scaling must be performed to fit the element viewport.</p>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Value</th>
   <td><strong>&lt;align&gt; &lt;meetOrSlice&gt;?</strong></td>
  </tr>
  <tr>
   <th scope="row">Default value</th>
   <td><code>xMidYMid</code> <code>meet</code></td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h3 id="symbol">symbol</h3>

<p>For {{SVGElement('symbol')}}, <code>preserveAspectRatio</code> indicates if a uniform scaling must be performed to fit the element viewport.</p>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Value</th>
   <td><strong>&lt;align&gt; &lt;meetOrSlice&gt;?</strong></td>
  </tr>
  <tr>
   <th scope="row">Default value</th>
   <td><code>xMidYMid</code> <code>meet</code></td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h3 id="view">view</h3>

<p>For {{SVGElement('view')}}, <code>preserveAspectRatio</code> indicates if a uniform scaling must be performed to fit the element viewport.</p>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Value</th>
   <td><strong>&lt;align&gt; &lt;meetOrSlice&gt;?</strong></td>
  </tr>
  <tr>
   <th scope="row">Default value</th>
   <td><code>xMidYMid</code> <code>meet</code></td>
  </tr>
  <tr>
   <th scope="row">Animatable</th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h2 id="Specification">Specification</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("Filters 1.0", "#element-attrdef-feimage-preserveaspectratio", "preserveAspectRatio")}}</td>
   <td>{{Spec2('Filters 1.0')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName("SVG2", "coords.html#PreserveAspectRatioAttribute", "preserveAspectRatio")}}</td>
   <td>{{Spec2("SVG2")}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName("SVG1.1", "coords.html#PreserveAspectRatioAttribute", "preserveAspectRatio")}}</td>
   <td>{{Spec2("SVG1.1")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>