Table-Layout: have one row get all space required (because of rowspan)

拜拜、爱过 提交于 2019-12-11 13:53:43

问题


I havea few complex data-table and am facing a problem with they layout: there is one cell wich gets a rowspan across all other rows, but the content of that cell is variable in height and may well exceed space required by all other rows.

something like this:

<table>
<tr><td style="height: 20px;">bla1</td><td rowspan="3">supa-col!</td></tr>
<tr><td style="height: 20px;">bla2</td></tr>
<tr><td style="height: 20px;">bla3</td></tr>
</table>

Now, lets look at that table again with a larger "supa-col":

<table>
<tr><td style="height: 20px;">bla1</td><td rowspan="3" style="height: 200px;">supa-col!</td></tr>
<tr><td style="height: 20px;">bla2</td></tr>
<tr><td style="height: 20px;">bla3</td></tr>
</table>

What happens when this is rendered is that the additional vspace required to include the rowspaning call gets distributed equally across the height of all cells.

What I would prefer is that space to be appended at the bottom of the last row, so that the distance between row 1 and 2 does not change. In other words: the size of that supa-col should not have an impact on the layout of all other calls... (I'd also be happy to append a final row which could get all the vetical filling that is needed...)

(Of course, in the real world, I do not know (or set) the heights in advance...)


回答1:


Just remove the height attribute from the last one...

 <tr><td>bla3</td></tr>



回答2:


You can use vertical-align on the td's. Css

td {
  vertical-align: top;
}

or

<table>
  <tr><td style="height: 20px;vertical-align:top;">bla1</td>
  <td rowspan="3" style="height: 200px;vertical-align:top;">supa-col!</td></tr>
  <tr><td style="height: 20px;vertical-align:top;">bla2</td></tr>
  <tr><td style="height: 20px;vertical-align:top;">bla3</td></tr>
</table>


来源:https://stackoverflow.com/questions/20128082/table-layout-have-one-row-get-all-space-required-because-of-rowspan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!