Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap table row to the next line

Tags:

html

css

<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.

like image 379
Leo Loki Avatar asked Jun 18 '13 02:06

Leo Loki


People also ask

How do you give a gap between rows?

The space between two rows in a table can be done using CSS border-spacing and border-collapse property. The border-spacing property is used to set the spaces between cells of a table and border-collapse property is used to specify whether the border of table is collapse or not.

Can you wrap a table row in a div?

You should not be doing that... is not a valid HTMl markup... Rows can not be wraped by divs.


2 Answers

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

like image 71
Jukka K. Korpela Avatar answered Oct 11 '22 10:10

Jukka K. Korpela


This can't be done with a table, the "row and column" grid is fixed.

However you could use inline-block elements:

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

CSS:

#container>div {display:inline-block;vertical-align:top} 
like image 42
Niet the Dark Absol Avatar answered Oct 11 '22 09:10

Niet the Dark Absol