32

Consider:

<table border="1" width="100%" ID="Table2">
    <tr>
        <td>100</td>
    </tr>
</table>

This code still leaves an "inch" of space on both sides of the table. I am trying to get the table to span the entire width of the page.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
T.T.T.
  • 33,367
  • 47
  • 130
  • 168

6 Answers6

23

Try (in your <head> section, or existing CSS definitions)...

<style>
  body {
    margin: 0;
    padding: 0;
  }
</style>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rog
  • 4,075
  • 2
  • 24
  • 35
17

There might be a margin style that your table is inheriting. Try setting the margin of the table to 0:

<table border="1" width="100%" ID="Table2" style="margin: 0px;">
  <tr>
    <td>100</td>
  </tr>
</table>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kevin Tighe
  • 20,181
  • 4
  • 35
  • 36
7
<table border="1" width="100%">

works for me.

Andrei Krasutski
  • 4,913
  • 1
  • 29
  • 35
user3154378
  • 79
  • 1
  • 1
5

You need to set the margin of the body to 0 for the table to stretch the full width. Alternatively, you can set the margin of the table to a negative number as well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tom Anderson
  • 10,807
  • 3
  • 46
  • 63
0

Just FYI:

html should be table and width: 100%.

span should be margin: auto;.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
harrrrrrry
  • 13,643
  • 2
  • 23
  • 28
  • What do you mean by *"html should be table"*? Can you elaborate? Preferably by [editing your answer](https://stackoverflow.com/posts/35944342/edit). But ***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today. – Peter Mortensen Aug 01 '21 at 22:06
-2

Just in case you're using Bootstrap 4, you can add px-0 (set left/right padding to 0) and mx-0 (set left/right margin to 0) CSS class to the body tag, like below:

<body class="px-0; mx-0">
    <!--your body HTML-->
</body>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
joym8
  • 4,014
  • 3
  • 50
  • 93