box-sizing-001.html (3904B)
1 <!DOCTYPE html> 2 <html> 3 <title>CSS Flexbox: box-sizing</title> 4 <link href="support/flexbox.css" rel="stylesheet"> 5 <link rel="help" href="https://drafts.csswg.org/css-flexbox/#flex-flow-property"> 6 <link rel="help" href="https://drafts.csswg.org/css-sizing-3/#box-sizing"> 7 <meta name="assert" content="This test checks the interactions between the flex layout mode and the two possible values for the box-sizing property: border-box and content-box" /> 8 9 <style> 10 .flexbox { 11 border: 2px solid orange; 12 } 13 .h3 { 14 height: 300px; 15 } 16 .w3 { 17 width: 300px; 18 } 19 .h4 { 20 height: 400px; 21 } 22 .w4 { 23 width: 400px; 24 } 25 .border-box, .flexbox > div { 26 box-sizing: border-box; 27 height: 100px; 28 width: 100px; 29 border: 2px solid lightblue; 30 border-top-width: 4px; 31 padding: 3px; 32 } 33 </style> 34 <script src="/resources/testharness.js"></script> 35 <script src="/resources/testharnessreport.js"></script> 36 <script src="/resources/check-layout-th.js"></script> 37 <body> 38 <div id=log></div> 39 40 All blue boxes are 100x100px with box-sizing: border-box and 2px border (4px border-top), we expect offsetWidth/Height to be <b>100x100</b> 41 42 <h3>flex-flow: default, orange box has width: 300px</h3> 43 <div class="flexbox" style="width: 300px"> 44 <div></div><div></div><div></div> 45 </div> 46 47 <h3>flex-flow: default, orange box has width: 400px</h3> 48 <div class="flexbox" style="width: 400px"> 49 <div></div><div></div><div></div> 50 </div> 51 52 <h3>flex-flow: default, orange box has width: auto</h3> 53 <div class="flexbox"> 54 <div></div><div></div><div></div> 55 </div> 56 57 <h3>flex-flow: default, orange box has width: auto, flex-box has box-sizing: border-box</h3> 58 <div class="flexbox border-box"> 59 <div data-expected-width=30></div> 60 <div data-expected-width=30></div> 61 <div data-expected-width=30></div> 62 </div> 63 64 <h3>flex-flow: column, red box has height: 300px</h3> 65 <div class="flexbox column" style="height: 300px"> 66 <div></div><div></div><div></div> 67 </div> 68 69 <h3>flex-flow: column, red box has height: 400px</h3> 70 <div class="flexbox column" style="height: 400px"> 71 <div></div><div></div><div></div> 72 </div> 73 74 <h3>flex-flow: column, red box has height: auto</h3> 75 <div class="flexbox column"> 76 <div></div><div></div><div></div> 77 </div> 78 79 <h3>flex-box has box-sizing: border-box and flex-wrap: wrap;</h3> 80 <div class="flexbox column wrap" style="box-sizing: border-box; border: 2px solid lightblue; padding: 3px; height: 200px; width: 100px; position: relative" data-expected-width=100 data-expected-height=200> 81 <div data-offset-x=3></div><div data-offset-x=103></div><div data-offset-x=203></div> 82 </div> 83 84 <h3>flex-box has box-sizing: default and flex-wrap: wrap;</h3> 85 <div class="flexbox column wrap" style="border: 2px solid lightblue; padding: 3px; height: 200px; width: 100px; position: relative" data-expected-width=110 data-expected-height=210> 86 <div data-offset-x=3></div><div data-offset-x=3></div><div data-offset-x=103></div> 87 </div> 88 89 <h3>flex-flow: column, flex-box has box-sizing: border-box, flex items have flex: 1</h3> 90 <div class="flexbox column" style="box-sizing: border-box; border: 2px solid lightblue; padding: 3px; height: 343px; width: 100px;" data-expected-width=100 data-expected-height=343> 91 <div style="flex: 1;" data-expected-height=111></div> 92 <div style="flex: 1;" data-expected-height=111></div> 93 <div style="flex: 1;" data-expected-height=111></div> 94 </div> 95 96 <script> 97 function addExpectedSizes(flexItem) { 98 if (!flexItem.hasAttribute('data-expected-height')) 99 flexItem.setAttribute('data-expected-height', 100); 100 if (!flexItem.hasAttribute('data-expected-width')) 101 flexItem.setAttribute('data-expected-width', 100); 102 } 103 [].forEach.call(document.querySelectorAll(".flexbox > div"), addExpectedSizes); 104 [].forEach.call(document.querySelectorAll(".border-box"), addExpectedSizes); 105 checkLayout('.flexbox'); 106 </script> 107 </body> 108 </html>