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