Monday, March 10

Why doesn't TABLE WIDTH="100%" use the full browser width?

html-table-tutorialThis is a common problem we face when we try to adjust width of table in HTML.Graphical browsers leave a narrow margin between the edge of the display area and the content.So when we set the table width=100% the browser will leave a margin for the table.To solve this problem we need to use some CSS tricks.





The code when table width=100% dose not use the full browser width

<html>
<head>
<title>Table</title>
</head>
<body>
<table width="100%" border="2px">
<tr>
<td>Name</td><td>Salary</td>
</tr>
<tr>
<td>Sam</td><td>$4500</td>
</tr>
<tr>
<td>Mark</td><td>$8500</td>
</tr>
<tr>
<td>Jhon</td><td>$1500</td>
</tr>
<tr>
<td>Maria</td><td>$6500</td>
</tr>
</table>
</body>
</html>


Output:



So to fix this problem we need to set  body{margin:0px;}  
So to fix this problem we nee 

The Code when table width=100% use the full browser width


<html>
<head>
<title>Table</title>
<style type="text/css">
body
{
 margin:0px;
}
</style>
</head>
<body>
<table width="100%" border="2px">
<tr>
<td>Name</td><td>Salary</td>
</tr>
<tr>
<td>Sam</td><td>$4500</td>
</tr>
<tr>
<td>Mark</td><td>$8500</td>
</tr>
<tr>
<td>Jhon</td><td>$1500</td>
</tr>
<tr>
<td>Maria</td><td>$6500</td>
</tr>
</table>
</body>
</html>



Output:


so, in this image we can see that the table using the full browser width.

If your table width=100% till dose not using the full browser width then post your problem on comment box.Thank you.