31

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,030
  • 21
  • 100
  • 124
T.T.T.
  • 31,761
  • 47
  • 124
  • 165

6 Answers6

23

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

<style>
  body {
    margin: 0;
    padding: 0;
  }
</style>
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Rog
  • 3,985
  • 2
  • 23
  • 34
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,030
  • 21
  • 100
  • 124
Kevin Tighe
  • 18,871
  • 4
  • 34
  • 36
6
<table border="1" width="100%">

works for me.

Andrei Krasutski
  • 4,205
  • 1
  • 24
  • 34
user3154378
  • 69
  • 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,030
  • 21
  • 100
  • 124
Tom Anderson
  • 10,667
  • 3
  • 45
  • 62
0

Just FYI:

html should be table and width: 100%.

span should be margin: auto;.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
harrrrrrry
  • 11,303
  • 1
  • 19
  • 27
  • 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,030
  • 21
  • 100
  • 124
joym8
  • 3,527
  • 2
  • 40
  • 84