views:

211

answers:

3

In Firefox, "C" is centered, due to the CSS blurb at the beginning. Why does IE7 left-justify it?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <style type="text/css">
td {
  text-align: center;
  width: 130px;
}
    </style>
  </head>

  <body>
    <div style="width: 300px; background-color: #888">
      <table>
        <tbody>
          <tr>
            <td>A</td>
            <td>B</td>
          </tr>
          <tr>
            <td colspan="2">C</td>
          </tr>
        </tbody>
      </table>
    </div>
  </body>
</html>
+3  A: 

That happens because you have width: 130px;. Try setting width only for the small cells, for example by:

td.span {
  width:auto;
}

<td colspan="2" class="span">C</td>

See example: http://jsbin.com/etoka
You can also do it the other way around - giving a class to the small cells, the whole row, or best: setting the width of the <table>.

Kobi
A: 

always use this for position a object in center in your page this feature is worked in all popular browser like IE FF Safari Chrome Opera

<center> This is my centered text</center>

please give me vote if your problem is solved

`<center>` is a deprecated tag. It works but you shouldn't use it. You should use `CSS` instead.
voyager
A: 

<center> is a deprecated tag. It may work but you shouldn't use it.

Chris
This belongs as a comment to the previous question. Anyway, you are right.
voyager