tags:

views:

52

answers:

3

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

+3  A: 

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>
Asaph
+1  A: 

Put

width="100%"

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

Kerry
While correct, this isn't good practice.
Alastair Pitts
Why not? I would disagree -- and while I don't use tables frequently, I have never run into a problem using that nor have I seen it stayed that it shouldn't be used.
Kerry
But what will happen to td width,it should get adjusted automatically is it..
Hulk
for once, inline styles are bad practice because they don't separate content from design. Here are some other reasons: http://webdesign.about.com/od/css/a/aa073106.htm
vitorbal
@vitorbal -- I didn't say anything about inline styles. It's an HTML property.@Hulk: Yes, it would get automatically adjusted to fit, unless you gave percentage values to the width of your td's.
Kerry
A: 

You might try using a css file in which you could write

table {
  width: 100%;
  height: 100%;
}

Or you can prepend following lines in your html file

<style type="text/css">
  table { width: 100%; height: 100%; }
</style>
TheMorph
You misspelled "height".
Asaph
@Asaph -- Thanks for the hint. It's so early in the morning. ;)
TheMorph