html 表格跨越整个宽度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/539309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:14:46  来源:igfitidea点击:

html table span entire width?

htmlhtml-table

提问by T.T.T.

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

This code still leaves and "inch" of space on both sides of the table. Trying to get the table to span the entire width of the page. Thanks.

这段代码仍然在桌子两侧留下“英寸”的空间。试图让表格跨越页面的整个宽度。谢谢。

采纳答案by Rog

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

尝试(在您的 <head> 部分或现有的 css 定义中)...

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

回答by Kevin Tighe

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

您的表格可能继承了边距样式。尝试将表格的边距设置为 0:

<table border="1" width="100%" ID="Table2" style="margin: 0px;">
<tr>
  <td>100</td>
</tr>
</table>

回答by user3154378

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

works for me.

为我工作。

回答by Tom Anderson

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.

您需要将正文的边距设置为 0,以便表格拉伸整个宽度。或者,您也可以将表格的边距设置为负数。

回答by harrrrrrry

Just FYI:

仅供参考:

html should be table & width:100%. span should be margin: auto;

html 应该是表格和宽度:100%。跨度应为边距:自动;