简体   繁体   English

将表格行换到下一行

[英]Wrap table row to the next line

<table id="table_id">
  <tr>
    <td>testtesttesttest</td>
    <td>testtesttesttest</td>
  </tr>
</table>

I would like that if the table does not fit on the screen, then to the second cell of the table will be transferred to another row down?我想如果表格在屏幕上放不下,那么表格的第二个单元格会被转移到另一行吗? Not the text in the cell, but the whole cell.不是单元格中的文本,而是整个单元格。

Change the cells to inline blocks:将单元格更改为内联块:

 #table_id { display: block; } #table_id td { display: inline-block; } td { background: green }
 <table id="table_id"> <tr> <td>testtesttesttest</td> <td>testtesttesttest</td> </tr> </table>

jsfiddle提琴手

This can't be done with a table, the "row and column" grid is fixed.这不能用表格来完成,“行和列”网格是固定的。

However you could use inline-block elements:但是,您可以使用inline-block元素:

<div id="container">
    <div>testtesttesttest</div>
    <div>testtesttesttest</div>
</div>

CSS: CSS:

#container>div {display:inline-block;vertical-align:top}

Improved upon Jukka's answer .改进了Jukka 的回答

HTML: HTML:

<table id="table_id">
<tr>
<td> testtesttesttest</td>
<td> testtesttesttest </td>
<td> testtesttesttest </td>
<td> testtesttesttest </td>
<td> testtesttesttest </td>
</tr>
<tr>
<td> testtesttesttest</td>
<td> testtesttesttest</td>
<td> testtesttesttest</td>
<td> testtesttesttest</td>
<td> testtesttesttest</td>
</tr>
</table>

CSS: CSS:

#table_id  {display: block; }
#table_id  td {display: inline-block; border: 3px solid #FFFFFF;}
td { background: green;
     border: 3px solid #FFFFFF;} /* to show cell sizes */

Visit http://jsfiddle.net/zjbyE/391访问http://jsfiddle.net/zjbyE/391

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

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