0

How to decrease the width of a table in html?

While working with tables in html, when i use too many <td> tags, the table's width gets too large to fit in my screen...how can i decrease this width?

24th Apr 2018, 4:40 AM
HMS
HMS - avatar
11 Respuestas
+ 4
The width attribute specifies the width of a table. If the width attribute is not set, a table takes up the space it needs to display the table data. <table width="400"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$80</td> </tr> </table> The width attribute of <table> is not supported in HTML5. Use CSS instead. CSS syntax: <table style="width:400px">
24th Apr 2018, 5:09 AM
Awele Omeligwe
Awele Omeligwe - avatar
+ 4
The reason is because your code is being interpreted as a HTML 4 doc and you are using HTML5 Tags which will not work...check for the default HTML5 template....add some bootstrap to make it flexible.
24th Apr 2018, 11:10 AM
Awele Omeligwe
Awele Omeligwe - avatar
+ 4
yes I am sure you will
24th Apr 2018, 11:15 AM
Awele Omeligwe
Awele Omeligwe - avatar
+ 3
Try and change table to this below code : <table border="1" style="width:300px"> this was your own code <table border="1" style="width=300px;">
24th Apr 2018, 6:06 AM
Awele Omeligwe
Awele Omeligwe - avatar
+ 2
can you share your code so dat we could see if there could be an error because html is not a forgiving language..
24th Apr 2018, 5:45 AM
Awele Omeligwe
Awele Omeligwe - avatar
+ 1
Thanks!
24th Apr 2018, 5:14 AM
HMS
HMS - avatar
+ 1
Tried that too... Now i can increase the size of the table (if i put 900px) but still can't decrease it... Maybe that's how it will always be?
24th Apr 2018, 11:07 AM
HMS
HMS - avatar
0
It didn't work 😶 The output was still the same
24th Apr 2018, 5:24 AM
HMS
HMS - avatar
0
Thanks. I still didn't learn html5 so i guess i should learn that first and then try it again
24th Apr 2018, 11:14 AM
HMS
HMS - avatar