/
index.md
665 lines (568 loc) · 17.8 KB
/
index.md
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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
---
title: preserveAspectRatio
slug: Web/SVG/Attribute/preserveAspectRatio
l10n:
sourceCommit: 904cdf09c7e328b7a15a6a4db6bc6bd31f969cce
---
{{SVGRef}}
**`preserveAspectRatio`** 属性は、指定されたアスペクト比を提供するビューボックスを持つ要素が、異なるアスペクト比を持つビューポートにどのように収まるべきかを示します。
SVG 画像のアスペクト比は {{SVGAttr('viewBox')}} 属性によって定義されるので、この属性が設定されていない場合、 **`preserveAspectRatio`** 属性は何の効果も持ちません(_後述する {{SVGElement('image')}} 要素は例外です_)。
## 例
### meet (width > height)
この例では、要素の `width` が `height` よりも大きい場合に `meet` を使用することを示しています。 3 つの配置値 `xMidYMid`、`xMinYMid`、`xMaxYMid` で 3 つのバリエーションを表示します。
```css hidden
html,
body,
svg {
height: 100%;
}
/* それぞれの iframe の本文に flex 要素を配置し、様々な画面サイズに対応できるようにした */
body {
display: flex;
}
```
```html
<svg viewBox="-1 -1 202 40" xmlns="http://www.w3.org/2000/svg">
<defs>
<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" />
</defs>
</svg>
```
```html
<rect x="0" y="0" width="60" height="30">
<title>xMidYMid meet</title>
</rect>
<svg
viewBox="0 0 100 100"
width="60"
height="30"
preserveAspectRatio="xMidYMid meet"
x="0"
y="0">
<use href="#smiley" />
</svg>
```
```html
<rect x="70" y="0" width="60" height="30">
<title>xMinYMid meet</title>
</rect>
<svg
viewBox="0 0 100 100"
width="60"
height="30"
preserveAspectRatio="xMinYMid meet"
x="70"
y="0">
<use href="#smiley" />
</svg>
```
```html
<rect x="140" y="0" width="60" height="30">
<title>xMaxYMid meet</title>
</rect>
<svg
viewBox="0 0 100 100"
width="60"
height="30"
preserveAspectRatio="xMaxYMid meet"
x="140"
y="0">
<use href="#smiley" />
</svg>
</svg>
```
```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;
}
```
{{EmbedLiveSample('meet width height', '100%', 200)}}
### slice (width > height)
この例では、要素の `width` が `height` よりも大きい場合に `slice` を使用することを示しています。 3 種類の配置値 `xMidYMin`、`xMidYMid`、`xMidYMax` で 3 つのバリエーションを表示します。
```css hidden
html,
body,
svg {
height: 100%;
}
/* それぞれの iframe の本文に flex 要素を配置し、様々な画面サイズに対応できるようにした */
body {
display: flex;
}
```
```html
<svg viewBox="-1 -1 202 57" xmlns="http://www.w3.org/2000/svg">
<defs>
<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" />
</defs>
</svg>
```
```html
<rect x="0" y="15" width="60" height="30">
<title>xMidYMin slice</title>
</rect>
<svg
viewBox="0 0 100 100"
width="60"
height="30"
preserveAspectRatio="xMidYMin slice"
x="0"
y="15">
<use href="#smiley" />
</svg>
```
```html
<rect x="70" y="15" width="60" height="30">
<title>xMidYMid slice</title>
</rect>
<svg
viewBox="0 0 100 100"
width="60"
height="30"
preserveAspectRatio="xMidYMid slice"
x="70"
y="15">
<use href="#smiley" />
</svg>
```
```html
<rect x="140" y="15" width="60" height="30">
<title>xMidYMax slice</title>
</rect>
<svg
viewBox="0 0 100 100"
width="60"
height="30"
preserveAspectRatio="xMidYMax slice"
x="140"
y="15">
<use href="#smiley" />
</svg>
</svg>
```
```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;
}
```
{{EmbedLiveSample('slice width height', '100%', 200)}}
### meet (height > width)
この例では、要素の `height` が `width` よりも大きい場合に `meet` を使用することを示しています。 3 種類の配置値 `xMidYMin`、`xMidYMid`、`xMidYMax` で 3 つのバリエーションを表示します。
```css hidden
html,
body,
svg {
height: 100%;
}
/* それぞれの iframe の本文に flex 要素を配置し、様々な画面サイズに対応できるようにした */
body {
display: flex;
}
```
```html
<svg viewBox="-1 -1 202 80" xmlns="http://www.w3.org/2000/svg">
<defs>
<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" />
</defs>
</svg>
```
```html
<rect x=0" y="0" width="30" height="75">
<title>xMidYMin meet</title>
</rect>
<svg
viewBox="0 0 100 100"
width="30"
height="75"
preserveAspectRatio="xMidYMin meet"
x="0"
y="0">
<use href="#smiley" />
</svg>
```
```html
<rect x="35" y="0" width="30" height="75">
<title>xMidYMid meet</title>
</rect>
<svg
viewBox="0 0 100 100"
width="30"
height="75"
preserveAspectRatio="xMidYMid meet"
x="35"
y="0">
<use href="#smiley" />
</svg>
```
```html
<rect x="70" y="0" width="30" height="75">
<title>xMidYMax meet</title>
</rect>
<svg
viewBox="0 0 100 100"
width="30"
height="75"
preserveAspectRatio="xMidYMax meet"
x="70"
y="0">
<use href="#smiley" />
</svg>
</svg>
```
```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;
}
```
{{EmbedLiveSample('meet height width', '100%', 200)}}
### slice (height > width)
この例では、要素の `height` が `width` よりも大きい場合に `slice` を使用することを示しています。 3 種類の配置値 `xMinYMid`、`xMidYMid`、`xMaxYMid` で 3 つのバリエーションを表示します。
```css hidden
html,
body,
svg {
height: 100%;
}
/* それぞれの iframe の本文に flex 要素を配置し、様々な画面サイズに対応できるようにした */
body {
display: flex;
}
```
```html
<svg viewBox="-1 -1 202 80" xmlns="http://www.w3.org/2000/svg">
<defs>
<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" />
</defs>
</svg>
```
```html
<rect x="0" y="0" width="30" height="75">
<title>xMinYMid slice</title>
</rect>
<svg
viewBox="0 0 100 100"
width="30"
height="75"
preserveAspectRatio="xMinYMid slice"
x="0"
y="0">
<use href="#smiley" />
</svg>
```
```html
<rect x="35" y="0" width="30" height="75">
<title>xMidYMid slice</title>
</rect>
<svg
viewBox="0 0 100 100"
width="30"
height="75"
preserveAspectRatio="xMidYMid slice"
x="35"
y="0">
<use href="#smiley" />
</svg>
```
```html
<rect x="70" y="0" width="30" height="75">
<title>xMaxYMid slice</title>
</rect>
<svg
viewBox="0 0 100 100"
width="30"
height="75"
preserveAspectRatio="xMaxYMid slice"
x="70"
y="0">
<use href="#smiley" />
</svg>
</svg>
```
```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;
}
```
{{EmbedLiveSample('slice height width', '100%', 200)}}
### none
この例では配置値を `none` に設定した要素を表示させています。
```css hidden
html,
body,
svg {
height: 100%;
}
/* それぞれの iframe の本文に flex 要素を配置し、様々な画面サイズに対応できるようにした */
body {
display: flex;
}
```
```html
<svg viewBox="-1 -1 192 62" xmlns="http://www.w3.org/2000/svg">
<defs>
<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" />
</defs>
</svg>
```
```html
<!-- none -->
<rect x="0" y="0" width="160" height="60">
<title>none</title>
</rect>
<svg
viewBox="0 0 100 100"
width="160"
height="60"
preserveAspectRatio="none"
x="0"
y="0">
<use href="#smiley" />
</svg>
</svg>
```
```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;
}
```
{{EmbedLiveSample('none ', '100%', 200)}}
## 構文
```plain
preserveAspectRatio="<align> [<meetOrSlice>]"
```
その値は、 1 つまたは 2 つのキーワードで構成されます。必要な配置値と、下記で記述されているオプションの "meet または slice" の参照です。
- 配置値
- : 配置値は、均等な変倍を強制するかどうかを示し、もしそうなら、{{ SVGAttr("viewBox") }}の縦横比がビューポートの縦横比と一致しない場合に使用する配置方法を示します。配置値は以下のいずれかのキーワードでなければなりません。
- **none**
均等な変倍を強制しません。指定された要素のグラフィックコンテンツを、要素の外接ボックスがビューポートの長方形に正確に一致するように、必要に応じて不均一に変倍します。 _もし `<align>` が `none` ならば、オプションの `<meetOrSlice>` の値は無視されることに注意してください_。
- **xMinYMin** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の `<min-x>` をビューポートの最小 X 値に配置します。
要素の {{ SVGAttr("viewBox") }} の `<min-y>` をビューポートの最小 Y 値に配置します。
- **xMidYMin** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の X の中央値をビューポートの X の中央値に配置します。
要素の {{ SVGAttr("viewBox") }} の `<min-y>` をビューポートの最小 Y 値に配置します。
- **xMaxYMin** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の `<min-x>+<width>` をビューポートの最大 X 値に配置します。
要素の {{ SVGAttr("viewBox") }} の `<min-y>` をビューポートの最小 Y 値に配置します。
- **xMinYMid** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の `<min-x>` をビューポートの最小 X 値に配置します。
要素の {{ SVGAttr("viewBox") }} の Y の中央値をビューポートの Y の中央値に配置します。
- **xMidYMid** (the default) - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の X の中央値をビューポートの X の中央値に配置します。
要素の {{ SVGAttr("viewBox") }} の Y の中央値をビューポートの Y の中央値に配置します。
- **xMaxYMid** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の `<min-x>+<width>` をビューポートの最大 X 値に配置します。
要素の {{ SVGAttr("viewBox") }} の Y の中央値をビューポートの Y の中央値に配置します。
- **xMinYMax** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の `<min-x>` をビューポートの最小 X 値に配置します。
要素の {{ SVGAttr("viewBox") }} の `<min-y>+<height>` をビューポートの最大 Y 値に配置します。
- **xMidYMax** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の X の中央値をビューポートの X の中央値に配置します。
要素の {{ SVGAttr("viewBox") }} の `<min-y>+<height>` をビューポートの最大 Y 値に配置します。
- **xMaxYMax** - 均等な変倍を強制します。
要素の {{ SVGAttr("viewBox") }} の `<min-x>+<width>` をビューポートの最大 X 値に配置します。
要素の {{ SVGAttr("viewBox") }} の `<min-y>+<height>` をビューポートの最大 Y 値に配置します。
- meet または slice の参照
- : meetまたはslice参照はオプションで、指定された場合は以下のキーワードのいずれかでなければなりません:
- **meet** (_the default_) - 次のようにグラフィックを変倍します。
- アスペクト比を維持されます。
- {{ SVGAttr("viewBox") }} 全体がビューポート内に表示されます。
- {{ SVGAttr("viewBox") }} は、他にも条件を満たしつつ、可能な限り拡大します。
この場合、グラフィックのアスペクト比がビューポートと一致しないと、ビューポートの一部が {{ SVGAttr("viewBox") }} の枠からはみ出してしまいます(つまり、{{ SVGAttr("viewBox") }} が描画する領域はビューポートよりも小さくなります)。
- **slice** - 次のようにグラフィックを変倍します。
- アスペクト比を維持されます。
- ビューポート全体が {{ SVGAttr("viewBox") }} に応じたものになります。
- {{SVGAttr("viewBox") }} は、他にも条件を満たしつつ、可能な限り縮小します。
この場合、 {{ SVGAttr("viewBox") }} のアスペクト比がビューポートと一致しないと、{{ SVGAttr("viewBox") }} の一部がビューポートの境界からはみ出してしまいます(つまり、{{ SVGAttr("viewBox") }} が描画する領域はビューポートよりも大きくなります)。
## 要素
この属性は以下の SVG 要素で使用することができます。
- {{SVGElement("svg")}}
- {{SVGElement("symbol")}}
- {{SVGElement("image")}}
- {{SVGElement("feImage")}}
- {{SVGElement("marker")}}
- {{SVGElement("pattern")}}
- {{SVGElement("view")}}
### feImage
{{SVGElement('feImage')}} の場合、 `preserveAspectRatio` は参照している画像が `<feImage>` 要素で定義した長方形に収まるように定義します。
<table class="properties">
<tbody>
<tr>
<th scope="row">値</th>
<td><strong><align> <meetOrSlice>?</strong></td>
</tr>
<tr>
<th scope="row">既定値</th>
<td><code>xMidYMid</code> <code>meet</code></td>
</tr>
<tr>
<th scope="row">アニメーション</th>
<td>可</td>
</tr>
</tbody>
</table>
### image
{{SVGElement('image')}} の場合、 `preserveAspectRatio` は参照している画像が `<feImage>` 要素で定義した長方形に収まるように定義します。
<table class="properties">
<tbody>
<tr>
<th scope="row">値</th>
<td><strong><align> <meetOrSlice>?</strong></td>
</tr>
<tr>
<th scope="row">既定値</th>
<td><code>xMidYMid</code> <code>meet</code></td>
</tr>
<tr>
<th scope="row">アニメーション</th>
<td>可</td>
</tr>
</tbody>
</table>
### marker
{{SVGElement('marker')}} の場合、 `preserveAspectRatio` は、要素のビューポートに合わせて一様に変倍する必要があるかどうかを示します。
<table class="properties">
<tbody>
<tr>
<th scope="row">値</th>
<td><strong><align> <meetOrSlice>?</strong></td>
</tr>
<tr>
<th scope="row">既定値</th>
<td><code>xMidYMid</code> <code>meet</code></td>
</tr>
<tr>
<th scope="row">アニメーション</th>
<td>可</td>
</tr>
</tbody>
</table>
### pattern
{{SVGElement('pattern')}} の場合、 `preserveAspectRatio` は、要素のビューポートに合わせて一様に変倍する必要があるかどうかを示します。
<table class="properties">
<tbody>
<tr>
<th scope="row">値</th>
<td><strong><align> <meetOrSlice>?</strong></td>
</tr>
<tr>
<th scope="row">既定値</th>
<td><code>xMidYMid</code> <code>meet</code></td>
</tr>
<tr>
<th scope="row">アニメーション</th>
<td>可</td>
</tr>
</tbody>
</table>
### svg
{{SVGElement('svg')}} の場合、 `preserveAspectRatio` は、要素のビューポートに合わせて一様に変倍する必要があるかどうかを示します。
<table class="properties">
<tbody>
<tr>
<th scope="row">値</th>
<td><strong><align> <meetOrSlice>?</strong></td>
</tr>
<tr>
<th scope="row">既定値</th>
<td><code>xMidYMid</code> <code>meet</code></td>
</tr>
<tr>
<th scope="row">アニメーション</th>
<td>可</td>
</tr>
</tbody>
</table>
### symbol
{{SVGElement('symbol')}} の場合、 `preserveAspectRatio` は、要素のビューポートに合わせて一様に変倍する必要があるかどうかを示します。
<table class="properties">
<tbody>
<tr>
<th scope="row">値</th>
<td><strong><align> <meetOrSlice>?</strong></td>
</tr>
<tr>
<th scope="row">既定値</th>
<td><code>xMidYMid</code> <code>meet</code></td>
</tr>
<tr>
<th scope="row">アニメーション</th>
<td>可</td>
</tr>
</tbody>
</table>
### view
{{SVGElement('view')}} の場合、 `preserveAspectRatio` は、要素のビューポートに合わせて一様に変倍する必要があるかどうかを示します。
<table class="properties">
<tbody>
<tr>
<th scope="row">値</th>
<td><strong><align> <meetOrSlice>?</strong></td>
</tr>
<tr>
<th scope="row">既定値</th>
<td><code>xMidYMid</code> <code>meet</code></td>
</tr>
<tr>
<th scope="row">アニメーション</th>
<td>可</td>
</tr>
</tbody>
</table>
## 仕様書
{{Specifications}}