Maintaining a fixed table width

I have a table with dynamic data.

Depending on the data, it expands or collapses.

I do not want it. I want a fixed width that never expands or collapses.

How can i do this?

I already tried <table width="300px"></table> but it does not work.

+6
html html-table
source share
3 answers

The following should work:

 <table style="width:300px;table-layout:fixed"></table> 
+12
source share

You would set the width of each column explicitly as follows:

 td.a { width:100px; } td.b { width:200px; } ... <table> <tr><td class='a'>A</td><td class='b'>B</td></tr> <tr><td class='a'>A</td><td class='b'>B</td></tr> <tr><td class='a'>A</td><td class='b'>B</td></tr> <tr><td class='a'>A</td><td class='b'>B</td></tr> </table> 
0
source share

Either the old ugly way

 <table width="300"></table> 

or CSS way

 <table style="width:300px"></table> 

Of course, the best way is to use a separate stylesheet file, call it, for example, style.css :

 table { width: 300px; } 

and your html document:

 <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css"/> </head> <body> <table> ... </table> </body> </html> 
-one
source share

All Articles