Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML table column of equal size

With the below code, I get the columns size being different (esp the last column is small) I would like to have all the three columns to be of same size.Thanks.

<html>
<body>
<h4>Two rows and three columns:</h4>
<table border="1" width="100%" height="400" align="top">
<tr style="height: 1">
  <td>
   <table width="100%" border="2" height ="100" align="top">
     <tr>
       <td>1-1</td>
       <td>1-2</td> 
     </tr>
     <tr>
       <td>1-3</td>
       <td>1-4</td>
     </tr>
   </table>
 </td> 
  <td>
   <table width="100%" border="2" height ="100" align="top">
     <tr>
       <td>2-1</td>
       <td>2-2</td> 
     </tr>
     <tr>
       <td>2-3</td>
       <td>2-4</td>
     </tr>
   </table>
<td>
   <table width="100%" border="2" height ="100" align="top">
     <tr>
       <td>3-1</td>
     </tr>
     <tr>     
       <td>3-2</td>
     </tr>
   </table>
 </td> 
</tr>
<tr style="vertical-align: top">
 </td> 
  <td>
   <table width="100%" border="2" height ="100">
     <tr>
       <td>4-1</td>
       <td>4-2</td> 
     </tr>
     <tr>
       <td>4-3</td>
       <td>4-4</td>
     </tr>
</table>
 <td>
   <table width="100%" border="2" height ="100">
     <tr>
       <td>5-1</td>
       <td>5-2</td> 
     </tr>
     <tr>
       <td>5-3</td>
       <td>5-4</td>
     </tr>
   </table>
<td> 
   <table width="100%" border="2" height ="100">
     <tr>
       <td>6-1</td>
     </tr>
     <tr>
       <td>6-3</td>
     </tr>
   </table>
</body>
</html>
like image 627
m4n07 Avatar asked Mar 25 '12 16:03

m4n07


People also ask

How do I make columns the same size in HTML?

Just add style="table-layout: fixed ; width: 100%;" inside <table> tag and also if you do not specify any styles and add just style=" width: 100%;" inside <table> You will be able to resolve it.

How do I make table cells the same size in HTML?

Using table-layout: fixed as a property for table and width: calc(100%/3); for td (assuming there are 3 td 's). With these two properties set, the table cells will be equal in size.

How do I fix the column size in HTML?

The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.


1 Answers

Insert a colgroup element in your table:

<table>
  <colgroup>
    <col style="width: 33%" />
    <col style="width: 33%" />
    <col style="width: 33%" />
  </colgroup>
  <tr>
...
  </tr>
</table>
like image 78
Sirko Avatar answered Oct 12 '22 00:10

Sirko