T.T.T.
T.T.T.

Reputation: 34623

HTML table span entire width

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.

Upvotes: 32

Views: 145665

Answers (6)

user3154378
user3154378

Reputation: 79

<table border="1" width="100%">

works for me.

Upvotes: 7

joym8
joym8

Reputation: 4232

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>

Upvotes: -2

harrrrrrry
harrrrrrry

Reputation: 14507

Just FYI:

html should be table and width: 100%.

span should be margin: auto;.

Upvotes: 0

Kevin Tighe
Kevin Tighe

Reputation: 21201

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>

Upvotes: 18

Tom Anderson
Tom Anderson

Reputation: 10827

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.

Upvotes: 5

Rog
Rog

Reputation: 4075

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

<style>
  body {
    margin: 0;
    padding: 0;
  }
</style>

Upvotes: 23

Related Questions