简体   繁体   English

如何将 3 列平均分成 2 列?

[英]How can I split 3 columns into 2 evenly?

I have the following React JSX code for a table:我有一个表的以下 React JSX 代码:

 <table> <tr> <td>col1</td> <td>col2</td> <td>col3</td> </tr> </table>

And I want to add a footer with 2 columns filling up the entire width but I'm having trouble doing that.我想添加一个 2 列填充整个宽度的页脚,但我无法做到这一点。 I tried colspan but its not working as expected.我尝试了 colspan 但它没有按预期工作。 How can I do this?我怎样才能做到这一点?

You can do this with colspan, all you need to take into account is that colspan should be integers (1,2,3) and cannot have something like 1.5.您可以使用 colspan 执行此操作,您需要考虑的是 colspan 应该是整数 (1,2,3) 并且不能有 1.5 之类的值。

So the trick is to also use colspan in your first row and give them all a colspan of 2, such that the total is 6 which you can divide by two columns of 3.所以诀窍是在你的第一行也使用 colspan 并给他们一个 colspan 2,这样总数是 6,你可以除以两列 3。

 <table border="1"> <tr> <td colspan="2">col1</td> <td colspan="2">col2</td> <td colspan="2">col3</td> </tr> <tr> <td colspan="3">footer1</td> <td colspan="3" >footer2</td> </tr> </table>

Just colspan your footer cell on all the 3 cells.只需在所有 3 个单元格上跨页脚单元格。 Then add a separate table within that footer table and make 2 columns.然后在该页脚表中添加一个单独的表并制作 2 列。 Don't forget to make that inner table as lean as possible (no border, no margin, .. as you need it)不要忘记使内表尽可能精简(没有边框,没有边距,..你需要它)

 <table border="1"> <tr> <td>col1</td> <td width="400">col2</td> <td>col3</td> </tr> <tr> <td colspan="3"> <table width="100%"> <tr> <td width="50%">footer left</td> <td width="50%">footer right</td> </tr> </table> </td> </tr> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM