flexbox-basic-img-vert-001.xhtml (3758B)
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!-- 3 Any copyright is dedicated to the Public Domain. 4 http://creativecommons.org/publicdomain/zero/1.0/ 5 --> 6 <!-- 7 This test checks that img elements behave correctly as flex items. 8 --> 9 <html xmlns="http://www.w3.org/1999/xhtml"> 10 <head> 11 <title>CSS Test: Testing flexbox layout algorithm property on img flex items in a vertical flex container</title> 12 <link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com"/> 13 <link rel="help" href="http://www.w3.org/TR/css-flexbox-1/#layout-algorithm"/> 14 <link rel="match" href="flexbox-basic-img-vert-001-ref.xhtml"/> 15 <style> 16 div.flexbox { 17 height: 200px; 18 background: lightgreen; 19 display: flex; 20 justify-content: space-between; 21 flex-direction: column; 22 float: left; 23 margin-right: 10px; 24 font: 8px monospace; 25 } 26 img { 27 width: 20px; 28 height: 10px; 29 min-height: 0; 30 border: 1px dotted green; 31 } 32 </style> 33 </head> 34 <body> 35 36 <!-- A) One flex item --> 37 <div class="flexbox"> 38 <img src="support/solidblue.png"/> 39 </div> 40 41 <!-- B) Text and an img (ensure they aren't merged into one flex item) --> 42 <div class="flexbox"> 43 a b <img src="support/solidblue.png"/> 44 </div> 45 46 <!-- C) Two img elements, getting stretched by different ratios, from 0. 47 48 Space-to-be-distributed = 200px - borders = 200 - (1 + 1) - (1 + 1) 49 = 196px 50 51 1st element gets 5/9 of space: 5/9 * 196px = 108.8px 52 1st element gets 4/9 of space: 4/9 * 196px = 87.1px 53 --> 54 <div class="flexbox"> 55 <img src="support/solidblue.png" style="flex: 5"/> 56 <img src="support/solidblue.png" style="flex: 4"/> 57 </div> 58 59 <!-- D) Two img elements, getting stretched by different ratios, from 60 different flex bases. 61 62 Space-to-be-distributed = 200px - (33 + 1 + 1) - (13 + 1 + 1) = 150px 63 1st element gets 2/5 of space: 33px + 2/5 * 150px = 93px 64 1st element gets 3/5 of space: 13px + 3/5 * 150px = 103px 65 --> 66 <div class="flexbox"> 67 <img src="support/solidblue.png" style="height: 33px; flex: 2 auto"/> 68 <img src="support/solidblue.png" style="height: 13px; flex: 3 auto"/> 69 </div> 70 71 <!-- E) Two flex items, getting shrunk by different amounts. 72 73 Space-to-be-distributed = 200px - (150 + 1 + 1) - (100 + 1 + 1) = -54px 74 First element scaled flex ratio = 4 * 150 = 600 75 Second element scaled flex ratio = 3 * 100 = 300 76 * So, total flexibility is 600 + 300 = 900 77 78 1st element gets 600/900 of space: 150 + 600/900 * -54 = 114px 79 2nd element gets 300/900 of space: 100 + 300/900 * -54 = 82px 80 --> 81 <div class="flexbox"> 82 <img src="support/solidblue.png" style="height: 150px; flex: 1 4 auto"/> 83 <img src="support/solidblue.png" style="height: 100px; flex: 1 3 auto"/> 84 </div> 85 86 <!-- F) Making sure we don't grow past max-height --> 87 <!-- Same as (D), except we've added a max-height on the second element. 88 --> 89 <div class="flexbox"> 90 <img src="support/solidblue.png" style="height: 33px; flex: 2 auto"/> 91 <img src="support/solidblue.png" 92 style="height: 13px; max-height: 90px; flex: 3 auto"/> 93 </div> 94 95 <!-- G) Making sure we grow at least as large as min-height --> 96 <!-- Same as (C), except we've added a min-height on the second element. 97 --> 98 <div class="flexbox"> 99 <img src="support/solidblue.png" style="height: 33px; flex: 2 auto"/> 100 <img src="support/solidblue.png" 101 style="height: 13px; min-height: 150px; flex: 3 auto"/> 102 </div> 103 104 </body> 105 </html>