visibility-collapse-rowspan-004-dynamic.html (6606B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <script src='/resources/testharness.js'></script> 4 <script src='/resources/testharnessreport.js'></script> 5 <link rel='stylesheet' href='support/base.css' /> 6 <link rel="author" title="Joy Yu" href="mailto:joysyu@mit.edu"> 7 <link rel="help" href="https://drafts.csswg.org/css-tables-3/#visibility-collapse-cell-rendering"> 8 <style> 9 table { 10 border-spacing: 0; 11 border-collapse: collapse; 12 } 13 table td { 14 border: 1px solid blue; 15 padding: 5px; 16 } 17 </style> 18 <main> 19 <h1>Visibility collapse</h1> 20 <a href="https://drafts.csswg.org/css-tables-3/#visibility-collapse-cell-rendering">Spec</a> 21 <p> 22 Setting a row to visibility:collapse changes table height but not width. 23 </p> 24 <table id="one"> 25 <tr id="firstRowRef"> 26 <td rowspan="5" id="spanningCellRef">B<br>B<br>B<br>B<br>B</td> 27 <td>first row</td> 28 </tr> 29 <tr id="secondRowRef"> 30 <td>aaaa</td> 31 </tr> 32 <tr> 33 <td>bbbb</td> 34 </tr> 35 <tr id="fourthRowRef"> 36 <td>cccc</td> 37 </tr> 38 <tr id="fifthRowRef"> 39 <td>dddd</td> 40 </tr> 41 </table> 42 In the bottom table, a row is dynamically collapsed, made visible, and collapsed again. 43 <table id="two"> 44 <tr id="firstRow"> 45 <td rowspan="5" id="spanningCell">B<br>B<br>B<br>B<br>B</td> 46 <td>first row</td> 47 </tr> 48 <tr id="secondRow"> 49 <td>aaaa</td> 50 </tr> 51 <tr id="thirdRow"> 52 <td>bbbb</td> 53 </tr> 54 <tr id="fourthRow"> 55 <td>cccc</td> 56 </tr> 57 <tr id="fifthRow"> 58 <td>dddd</td> 59 </tr> 60 </table> 61 </main> 62 63 <script> 64 function runTests() { 65 for (i = 0; i< tests.length; i++) { 66 test(function() 67 { 68 assert_equals.apply(this, tests[i]); 69 }, 70 tests[i][2]); 71 }; 72 } 73 function width(element) { 74 return element.getBoundingClientRect().width; 75 } 76 function height(element) { 77 return element.getBoundingClientRect().height; 78 } 79 document.getElementById("thirdRow").style.visibility = "collapse"; 80 tests = [ 81 [ 82 width(document.getElementById('two')), 83 width(document.getElementById('one')), 84 "spanning row visibility:collapse doesn't change table width" 85 ], 86 [ 87 height(document.getElementById('firstRow')), 88 height(document.getElementById('firstRowRef')), 89 "when third row is collapsed, first row stays the same height" 90 ], 91 [ 92 height(document.getElementById('secondRow')), 93 height(document.getElementById('secondRowRef')), 94 "when third row is collapsed, second row stays the same height" 95 ], 96 [ 97 height(document.getElementById('thirdRow')), 98 0, 99 "third row visibility:collapse makes row height 0" 100 ], 101 [ 102 height(document.getElementById('fourthRow')), 103 height(document.getElementById('fourthRowRef')), 104 "when third row is collapsed, fourth row stays the same height" 105 ], 106 [ 107 height(document.getElementById('spanningCell')), 108 height(document.getElementById('firstRow')) + 109 height(document.getElementById('secondRow')) + 110 height(document.getElementById('fourthRow')) + 111 height(document.getElementById('fifthRow')), 112 "spanning cell shrinks to sum of remaining three rows' height" 113 ]]; 114 runTests(); 115 document.getElementById("thirdRow").style.visibility = "visible"; 116 tests = [ 117 [ 118 height(document.getElementById('firstRow')), 119 height(document.getElementById('firstRowRef')), 120 "when third row is visible, first row stays the same height" 121 ], 122 [ 123 height(document.getElementById('secondRow')), 124 height(document.getElementById('secondRowRef')), 125 "when third row is visible, second row stays the same height" 126 ], 127 [ 128 height(document.getElementById('thirdRow')), 129 height(document.getElementById('secondRowRef')), 130 "when third row is visible, third row stays the same height" 131 ], 132 [ 133 height(document.getElementById('fourthRow')), 134 height(document.getElementById('fourthRowRef')), 135 "when third row is visible, fourth row stays the same height" 136 ], 137 [ 138 height(document.getElementById('fifthRow')), 139 height(document.getElementById('fifthRowRef')), 140 "when third row is visible, fifth row stays the same height" 141 ], 142 [ 143 height(document.getElementById('spanningCell')), 144 height(document.getElementById('spanningCellRef')), 145 "when third row is visible, spanning cell stays the same height" 146 ]]; 147 runTests(); 148 document.getElementById("thirdRow").style.visibility = "collapse"; 149 tests = [ 150 [ 151 width(document.getElementById('two')), 152 width(document.getElementById('one')), 153 "(2nd collapse) spanning row visibility:collapse doesn't change table width" 154 ], 155 [ 156 height(document.getElementById('firstRow')), 157 height(document.getElementById('firstRowRef')), 158 "when third row is collapsed again, first row stays the same height" 159 ], 160 [ 161 height(document.getElementById('secondRow')), 162 height(document.getElementById('secondRowRef')), 163 "when third row is collapsed again, second row stays the same height" 164 ], 165 [ 166 height(document.getElementById('thirdRow')), 167 0, 168 "(2nd collapse) third row visibility:collapse makes row height 0" 169 ], 170 [ 171 height(document.getElementById('fourthRow')), 172 height(document.getElementById('fourthRowRef')), 173 "when third row is collapsed again, fourth row stays the same height" 174 ], 175 [ 176 height(document.getElementById('spanningCell')), 177 height(document.getElementById('firstRow')) + 178 height(document.getElementById('secondRow')) + 179 height(document.getElementById('fourthRow')) + 180 height(document.getElementById('fifthRow')), 181 "(2nd collapse) spanning cell shrinks to sum of remaining three rows' height" 182 ]]; 183 runTests(); 184 </script> 185 </html>