background-size-cover-contain-001.xht (2414B)
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 2 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 5 <head> 6 7 <title>CSS Backgrounds and Borders Test: background-size - cover value and contain value</title> 8 9 <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/" /> 10 <link rel="help" href="http://www.w3.org/TR/css3-background/#the-background-size" title="3.9. Sizing Images: the 'background-size' property" /> 11 <link rel="match" href="../../reference/ref-filled-green-100px-square.xht" /> 12 13 <meta name="flags" content="image" /> 14 <meta name="assert" content="When 'background-size' is 'cover', then the background-image is scaled, while preserving its intrinsic aspect ratio (it is 1:1 in this test), to the smallest size such that both its width and its height can completely cover the background positioning area. When 'background-size' is 'contain', then the background-image is scaled, while preserving its intrinsic aspect ratio (it is 1:1 in this test), to the largest size such that both its width and its height can fit inside the background positioning area. In this test, the 2 background-images should be scaled to become 100px by 100px." /> 15 16 <style type="text/css"><![CDATA[ 17 div#overlapped-red 18 { 19 background-image: url("support/200x200-red.png"); 20 background-repeat: no-repeat; 21 background-size: contain; 22 height: 150px; 23 padding: 25px; 24 width: 50px; 25 /* 26 background positioning area is 100px wide by 200px tall. 27 The largest size that can fit inside it with a 1:1 ratio 28 is 100px by 100px. So, the background image should be 29 scaled to 100px by 100px. 30 */ 31 } 32 33 div#overlapping-green 34 { 35 background-image: url("support/50x50-green.png"); 36 background-repeat: no-repeat; 37 background-size: cover; 38 border-bottom: transparent solid 50px; 39 bottom: 200px; 40 height: 0px; 41 padding: 25px; 42 position: relative; 43 width: 50px; 44 45 /* 46 background positioning area to cover is 100px wide by 47 50px tall. The smallest size that can completely cover 48 it with a 1:1 ratio is 100px by 100px. So, the 49 background image should be scaled to 100px by 100px. 50 */ 51 } 52 ]]></style> 53 54 </head> 55 56 <body> 57 58 <p>Test passes if there is a filled green square and <strong>no red</strong>.</p> 59 60 <div id="overlapped-red"></div> 61 62 <div id="overlapping-green"></div> 63 64 </body> 65 </html>