stretch-inline-size-001.html (7977B)
1 <!DOCTYPE html> 2 <link rel="help" href="https://drafts.csswg.org/css-sizing-4/#sizing-values"> 3 <link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/check-layout-th.js"></script> 7 <meta name="assert" 8 content="inline-size:stretch (setting 'width' in this case) causes an element's content-box to be sized such that its margin-box-size will fill the containing block's content-box."> 9 <style> 10 .cb { 11 inline-size: 50px; 12 block-size: 40px; 13 14 /* This margin & border are purely cosmetic and don't impact the sizing 15 * calculations in this test: */ 16 margin: 5px; 17 border: 2px solid black; 18 19 /* This padding only comes into play for the subtests with absolutely 20 * positioned children (where our padding-box forms the containing block 21 * for the abspos child). */ 22 padding-inline: 5px; 23 padding-block: 3px; 24 25 /* We make each containing block an inline-level box, so we can display 26 * subtests in multiple rows, for easier visualization: */ 27 display: inline-block; 28 vertical-align: top; 29 } 30 31 .test { 32 /* We have 2+3 = 5px of margin in the inline axis. This means the stretched 33 * children should all have a border-box size that's 5px less than the 34 * containing block's content-box size, i.e. 50 - 5 = 45px. */ 35 margin-inline-start: 2px; 36 margin-inline-end: 3px; 37 38 /* We also have some border/padding that UAs will need to account for 39 * when computing the stretched children's content-box sizes; but these 40 * don't reduce our `data-expected-width` expectations, since those 41 * correspond to the border-box size. */ 42 border: 3px solid blue; 43 padding: 2px; 44 45 inline-size: stretch; 46 block-size: 20px; 47 background: fuchsia; 48 } 49 </style> 50 <script> 51 function runTests() { 52 checkLayout('[data-expected-width]'); 53 54 // Add box-sizing:border-box (which shouldn't impact the actual resolved 55 // box sizes that 'stretch' produces), and retest: 56 for (let elem of document.querySelectorAll(".test")) { 57 elem.style.boxSizing = "border-box"; 58 } 59 checkLayout('[data-expected-width]'); 60 } 61 </script> 62 <body onload="runTests()"> 63 <!-- 'stretch' on a block box, replaced element, form controls, float: --> 64 <div class="cb"> 65 <div class="test" data-expected-width="45"></div> 66 </div> 67 <div class="cb"> 68 <canvas class="test" data-expected-width="45"></canvas> 69 </div> 70 <div class="cb"> 71 <input class="test" data-expected-width="45"> 72 </div> 73 <div class="cb"> 74 <textarea class="test" data-expected-width="45"></textarea> 75 </div> 76 <div class="cb"> 77 <button class="test" data-expected-width="45"></button> 78 </div> 79 <div class="cb"> 80 <div class="test" style="float: left" data-expected-width="45"></div> 81 </div> 82 83 <br> 84 85 <!-- 'stretch' on various abspos configurations, which use the container's 86 padding-box as the area-to-fill (which in this case is 10px larger than 87 the container's content-box, hence the larger 'data-expected-*' 88 values vs. the previous subtests). --> 89 <!-- With 0 insets, the child's margin-box fills the CB's padding-box, so 90 the child's border-box should end being 91 cb-padding-box-size - child-margin-size = 60px - 5px = 55px --> 92 <div class="cb" style="position: relative"> 93 <div class="test" style="position: absolute; inset-inline: 0;" 94 data-expected-width="55"></div> 95 </div> 96 97 <!-- With auto insets, the child is placed at its static position which is 98 the origin of the CB's content-box, and then 'stretch' makes it extend 99 to reach the far end of the CB's padding-box. So it should be as large 100 as the zero-insets case above, minus the CB's inline-start-padding 101 which is 5px. --> 102 <div class="cb" style="position: relative"> 103 <div class="test" style="position: absolute" data-expected-width="50"></div> 104 </div> 105 106 <!-- When we specify an inset, the child should be as large as the 107 zero-insets case above, minus whatever nonzero inset we choose. --> 108 <div class="cb" style="position: relative"> 109 <div class="test" style="position: absolute; inset-inline-start: 10px" 110 data-expected-width="45"></div> 111 </div> 112 <div class="cb" style="position: relative"> 113 <div class="test" style="position: absolute; inset-inline-end: 10px" 114 data-expected-width="45"></div> 115 </div> 116 117 <!-- If an inset pushes the child past the edge of the CB, 'stretch' shrinks 118 to just the 10px needed for the child's border/padding: --> 119 <div class="cb" style="position: relative"> 120 <div class="test" style="position: absolute; inset-inline-end: 55px" 121 data-expected-width="10"></div> 122 </div> 123 <div class="cb" style="position: relative"> 124 <div class="test" style="position: absolute; inset-inline-start: 55px" 125 data-expected-width="10"></div> 126 </div> 127 128 <br> 129 130 <!-- 'stretch' on various abspos configurations in a grid: similar to 131 above, but the grid area forms the containing block. --> 132 <!-- Similar to zero insets case above, but just now in a grid: --> 133 <div class="cb" 134 style="display: inline-grid; position: relative"> 135 <div class="test" 136 style="position: absolute; inset-inline: 0;" 137 data-expected-width="55"></div> 138 </div> 139 140 <!-- With no insets, we're placed at our static position which is the grid's 141 padding-box origin, and then we stretch to reach the far end of its 142 padding-box. So we should be as large as the zero-insets case above. --> 143 <div class="cb" 144 style="display: inline-grid; position: relative"> 145 <div class="test" 146 style="position: absolute" 147 data-expected-width="55"></div> 148 </div> 149 150 <!-- When we specify an inset, the child should be as large as the 151 zero-insets case above, minus whatever nonzero inset we choose. --> 152 <div class="cb" 153 style="display: inline-grid; position: relative"> 154 <div class="test" 155 style="position: absolute; inset-inline-start: 10px" 156 data-expected-width="45"></div> 157 </div> 158 <div class="cb" 159 style="display: inline-grid; position: relative"> 160 <div class="test" 161 style="position: absolute; inset-inline-end: 10px" 162 data-expected-width="45"></div> 163 </div> 164 165 <!-- If an inset pushes the child past the edge of the CB, 'stretch' shrinks 166 to just the 10px needed for the child's border/padding: --> 167 <div class="cb" 168 style="display: inline-grid; position: relative"> 169 <div class="test" 170 style="position: absolute; inset-inline-end: 55px" 171 data-expected-width="10"></div> 172 </div> 173 <div class="cb" 174 style="display: inline-grid; position: relative"> 175 <div class="test" 176 style="position: absolute; inset-inline-start: 55px" 177 data-expected-width="10"></div> 178 </div> 179 180 <br> 181 182 <!-- 'stretch' on a flex item: --> 183 <div class="cb" style="display: inline-flex; flex-direction: row"> 184 <div class="test" data-expected-width="45"></div> 185 </div> 186 <div class="cb" style="display: inline-flex; flex-direction: column"> 187 <div class="test" data-expected-width="45"></div> 188 </div> 189 <!--...now with an extra-large sibling sharing the child's flex line, to be 190 sure our 'stretch' sizing value resolves against the flex line's size: --> 191 <div class="cb" style="display: inline-flex; flex-flow: column wrap"> 192 <div class="test" data-expected-width="55"></div> 193 <div style="inline-size: 60px"></div> 194 </div> 195 196 <!-- 'stretch' on a grid item in a definite-size grid track: --> 197 <div class="cb" style="display: inline-grid; grid-template-columns: 35px"> 198 <div class="test" data-expected-width="30"></div> 199 </div> 200 201 <!-- 'stretch' on a grid item in an automatically-sized grid track: --> 202 <div class="cb" style="display: inline-grid"> 203 <div class="test" data-expected-width="45"></div> 204 </div> 205 </body>