background-size-cover-contain-001

background-size - cover value and contain value

WeasyPrint

Reference (good) by WeasyPrint

Reference (good) by this browser

This browser

Flags
image
Assertion
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.

Source

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