Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

table cell width issue

Tags:

html

css

I have a table with 2 rows where i need varying cell width as

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

I cannot get the width as specified the second row also gets the width of the first row.

like image 792
user544079 Avatar asked May 09 '11 13:05

user544079


People also ask

How do you fix a cell width in a table?

Select your table. On the Layout tab, in the Cell Size group, click AutoFit. Click Fixed Column Width.

How do I fix td width in CSS?

By using CSS, the styling of HTML elements is easy to modify. To fix the width of td tag the nth-child CSS is used to set the property of specific columns(determined by the value of n) in each row of the table.

How do you adjust the width of a TD table?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.


1 Answers

to do this with one table you need to introduce more columns and then get the column widths by using colspan so you can get the combined widths you require

to get this to work well across browser you will possibly need to use the <col> and <colgroup> elements : http://www.w3.org/TR/html401/struct/tables.html#h-11.2.4

<body bgcolor="#14B3D9">
<table width="100%" border="1" bgcolor="#ffffff">
<colgroup>
<col width="25%">
<col width="25%">
<col width="25%">
<col width="5%">
<col width="20%">
</colgroup>

    <tr>
        <td>25</td>
        <td colspan="2">50</td>
        <td colspan="2">25</td>     
    </tr>
    <tr>
        <td colspan="2">50</td>
        <td colspan="2">30</td>
        <td>20</td>
    </tr>
</table>
</body>
like image 169
clairesuzy Avatar answered Sep 20 '22 18:09

clairesuzy