How do I make my table body width equal to the table width in HTML?
A:
I will assume for the purpose of this answer that your HTML is like such:
<html>
<head>
<style type="text/css">
table.onetable {
width: 100%;
background-color: #F00;
margin: 0;
}
</style>
</head>
<body>
<table class="onetable">
<tr>
<td>Hello World</td>
</tr>
</table>
</body>
</html>
The reason why your table isn't filling the body
is because your browser's default style imposes a padding to your body
tag (usually 8px on most user-agents). Use the following CSS to override that style:
body { margin: 0; padding: 0; }
Andrew Moore
2009-07-23 17:48:17
+1
A:
You might also try setting the border-collapse style on your table to "collapse". This will minimize any padding on the table created by the browser defaults.
table {
border-collapse: collapse;
}
skybondsor
2009-07-23 21:25:46