Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto width on tables

Tags:

html

css

A html table cols and rows are generated dynamically,

i.e, for the first instance it could be two rows and there columns. and next time it could be two rows and 10 columns

My question is how to adjust the with automatically of the table so that the table always appears 100% in the page adjusting the coulmn size and row size

    <table>
    <tr><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td></tr>
    </table>

    <table>
     <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
     <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
     <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
  </table>

Thanks..

like image 759
Hulk Avatar asked May 19 '10 06:05

Hulk


People also ask

How do you set the width of a table?

To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.

How do I fix the width of a table 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.


2 Answers

Using CSS:

<style type="text/css">
table { width: 100%; }
</style>
<table>
...
</table>

or using a CSS inline style:

<table style="width: 100%">
...
</table>

or using old school HTML:

<table width="100%">
...
</table>
like image 190
Asaph Avatar answered Sep 23 '22 06:09

Asaph


Put

width="100%"

In your table tag -- it will always be 100% width. Is that what you meant?

like image 33
Kerry Jones Avatar answered Sep 20 '22 06:09

Kerry Jones