Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html table cell width for different rows [duplicate]

Tags:

html

css

Possible Duplicate:
table cell width issue

I have a table set up as

<html>  <body bgcolor="#14B3D9"> <table width="100%" border="1" bgcolor="#ffffff">     <tr>         <td width="25%">25</td>         <td width="50%">50</td>         <td width="25%">25</td>     </tr>     <tr>         <td width="50%">50</td>         <td width="30%">30</td>         <td width="20%">20</td>     </tr> </table> </body> </html> 

How do i get the 2 rows to have different cell width?

like image 312
user544079 Avatar asked May 09 '11 14:05

user544079


People also ask

Is it allowed to use different column widths in HTML?

HTML tables can have different sizes for each column, row or the entire table. Use the style attribute with the width or height properties to specify the size of a table, row or column.

How do I auto adjust column width in HTML?

If the text is non wrapping text then you set the cell to width:1px and use white-space:nowrap. The text in that column will then determine the width of the cell. It's a technique commonly used for images and captions (without the white-space:nowrap) and allows text to wrap at the limits of an image automatically.

What does table-layout fixed do?

When table-layout: fixed is applied, the content no longer dictates the layout, but instead, the browser uses any defined widths from the table's first row to define column widths. If no widths are present on the first row, the column widths are divided equally across the table, regardless of content inside the cells.

Should I still use HTML tables?

When should you NOT use HTML tables? HTML tables should be used for tabular data — this is what they are designed for. Unfortunately, a lot of people used to use HTML tables to lay out web pages, e.g. one row to contain the header, one row to contain the content columns, one row to contain the footer, etc.


1 Answers

One solution would be to divide your table into 20 columns of 5% width each, then use colspan on each real column to get the desired width, like this:

<html>  <body bgcolor="#14B3D9">  <table width="100%" border="1" bgcolor="#ffffff">      <colgroup>          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">          <col width="5%"><col width="5%">      </colgroup>      <tr>          <td colspan=5>25</td>          <td colspan=10>50</td>          <td colspan=5>25</td>      </tr>      <tr>          <td colspan=10>50</td>          <td colspan=6>30</td>          <td colspan=4>20</td>      </tr>  </table>  </body>  </html>

JSFIDDLE

like image 161
TokPhobia Avatar answered Sep 24 '22 02:09

TokPhobia