replaced-element-023.html (1092B)
1 <!DOCTYPE html> 2 <html> 3 <title>CSS aspect-ratio: canvas with aspect-ratio and contain:size</title> 4 <link rel="author" title="Ting-Yu Lin" href="mailto:tlin@mozilla.com"> 5 <link rel="author" title="Mozilla" href="https://www.mozilla.org/"> 6 <link rel="help" href="https://drafts.csswg.org/css-sizing-4/#aspect-ratio"> 7 <link rel="help" href="https://github.com/w3c/csswg-drafts/issues/5550"> 8 <link rel="match" href="../../reference/ref-filled-green-100px-square.xht"> 9 <meta name="assert" content="This test verifies aspect-ratio's <ratio> is used to determine the canvas' size because contain:size enforces no intrinsic aspect ratio."> 10 11 <style> 12 canvas { 13 width: 100px; 14 aspect-ratio: 1/1; 15 contain: size; 16 } 17 </style> 18 19 <script> 20 window.onload = function() { 21 const canvas = document.querySelector('canvas'); 22 const ctx = canvas.getContext('2d'); 23 ctx.fillStyle = 'green'; 24 ctx.fillRect(0, 0, 200, 200); 25 } 26 </script> 27 28 <p>Test passes if there is a filled green square and <strong>no red</strong>.</p> 29 <canvas width=200 height=200></canvas> 30 </html>