Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /svg/embedded/image-preserveaspectratio-meet-svg-with-size.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>preserveAspectRatio on an image element fits a referenced SVG that has a width and height</title>
<link rel="author" title="Sam Weinig" href="mailto:sam@webkit.org">
<link rel="match" href="image-preserveaspectratio-meet-svg-with-size-ref.html">
<meta name="assert" content="The image element's preserveAspectRatio fits the referenced SVG's natural aspect ratio into the positioning rectangle, and the result is the SVG viewport it is rendered in: with xMinYMid meet a square SVG in a 200x100 rectangle is a 100x100 square at the left edge, whatever the SVG root's own preserveAspectRatio would do.">
<style>
body { margin: 0; }
</style>
<!-- Red is painted where the image must be, so an image drawn anywhere else, or not cropped, leaves red showing. -->
<svg width="220" height="120">
<rect x="10" y="10" width="100" height="100" fill="red"/>
<image x="10" y="10" width="200" height="100" preserveAspectRatio="xMinYMid meet" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><rect width='100' height='100' fill='rgb(0,128,0)'/></svg>"/>
</svg>