views:

32

answers:

2

I have HTML page that appears in browser as:

alt text

I want to make the page to appear centered and compact as:

alt text

I made the borders visible in the first picture to reveal the structure.

Here is the HTML source code:

<html>
<head>
  <title></title>
</head>
<body>
<div id="body">
<div id="masthead">
<table border="1" cellpadding="0" cellspacing="0" width="20%">
  <tbody>
    <tr>
      <td><b>Shipment #</b></td>
      <td>ADD TEXT</td>
    </tr>
    <tr>
      <td><b>Invoice #</b></td>
      <td>ADD TEXT</td>
    </tr>
    <tr>
      <td><b>Customer PO</b></td>
      <td>ADD TEXT</td>
    </tr>
  </tbody>
</table>
<br/>
<h1 align="center">PACKING LIST</h1>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
    <tr>
      <td width="50%"><b><u>Package Consists the Following Items:</u><br/><br/></b></td>
    </tr>
</tbody>
</table>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
    <tr>
      <td width="7%">1.</td>
      <td>Item Name</td>
      <td>Show Qty.</td>
    </tr>
    <tr>
      <td width="7%">2.</td>
      <td>Item Name</td>
      <td>Show Qty.</td>
    </tr>
    <tr>
      <td width="7%">3.</td>
      <td>Item Name</td>
      <td>Show Qty.</td>
    </tr>
  </tbody>
</table>
<br/><br/>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tbody>
    <tr>
      <td width="30%"><b><u>Distributor</u></b></td>
      <td><b><u>Printed on</u></b></td>
    </tr>
    <tr>
      <td><b><font color="#333399">SAMPLE COMPANY</font></b></td>
      <td>5/3/2010</td>
    </tr>
</tbody>
</table>
</body>
</html>
+1  A: 

Try this CSS:

html, body{
  text-align:center; /* fix for ie7 */
}

div#body{
  margin:0px auto;
  width:800px; /* adjust width */
  text-align:left;
}
Sarfraz
I will try it .....
Beginner_Pal
+2  A: 

Put your content in a "container" div that's set to a specific width and them set the left and right margins to "auto" (margin: 0px auto 0px auto) (the margin values refer to top, right, bottom and left in that order, same for padding in css) in the css.

<html>
<head>
  <title></title>
</head>

<style type="text/css">
.container {
    width: 760px;
    margin: 0px auto 0px auto;
}
</style>

<body>
<div id="body">

<div class="container">

<div id="masthead">
<table border="1" cellpadding="0" cellspacing="0" width="20%">
  <tbody>
    <tr>
      <td><b>Shipment #</b></td>
      <td>ADD TEXT</td>
    </tr>
    <tr>
      <td><b>Invoice #</b></td>
      <td>ADD TEXT</td>
    </tr>
    <tr>
      <td><b>Customer PO</b></td>
      <td>ADD TEXT</td>
    </tr>
  </tbody>
</table>
<br/>
<h1 align="center">PACKING LIST</h1>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
    <tr>
      <td width="50%"><b><u>Package Consists the Following Items:</u><br/><br/></b></td>
    </tr>
</tbody>
</table>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
 <tbody>
    <tr>
      <td width="7%">1.</td>
      <td>Item Name</td>
      <td>Show Qty.</td>
    </tr>
    <tr>
      <td width="7%">2.</td>
      <td>Item Name</td>
      <td>Show Qty.</td>
    </tr>
    <tr>
      <td width="7%">3.</td>
      <td>Item Name</td>
      <td>Show Qty.</td>
    </tr>
  </tbody>
</table>
<br/><br/>
<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tbody>
    <tr>
      <td width="30%"><b><u>Distributor</u></b></td>
      <td><b><u>Printed on</u></b></td>
    </tr>
    <tr>
      <td><b><font color="#333399">SAMPLE COMPANY</font></b></td>
      <td>5/3/2010</td>
    </tr>
</tbody>
</table>

</div>

</body>
</html>
tomvon
Thanks ..... Solved
Beginner_Pal