0

How could I center the single cell inside a tr, is there a property that I'm not aware of perhaps? So, I would like that single cell to be centered no matter how many cells will be added above or below, if that's possible..? This is in the context of an email template.

td {
  border: 1px solid blue;
  padding: 50px;  
}

.center {
  padding: 0;
}
<table id="main">
  <tr>
    <td>
      <table>
        <tr>
          <td></td>
          <td></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table>
        <tr>
          <td class="center">center me please</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table>
        <tr>
          <td></td>
          <td></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Smithy
  • 807
  • 5
  • 17
  • 43

2 Answers2

0

just add align="center" to the table which you want to make center

td {
  border: 1px solid blue;
  padding: 50px;  
}

.center {
  padding: 0;
}
<table id="main">
  <tr>
    <td>
      <table>
        <tr>
          <td></td>
          <td></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table align="center">
        <tr>
          <td class="center">center me please</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table>
        <tr>
          <td></td>
          <td></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
Zuber
  • 3,393
  • 1
  • 19
  • 34
  • 1
    NO : https://www.w3schools.com/tags/att_table_align.asp --> **The align attribute of is not supported in HTML5. Use CSS instead.**
    – Temani Afif May 14 '18 at 11:36
  • @smithy please don't accept this answer and don't use it ... it provides an obselete non supported way to center, refer to the link I shared. – Temani Afif May 14 '18 at 11:50
  • This is the right/easiest way of doing it if you're building html email – gj-wes May 15 '18 at 08:03
0

Simple Apply left and right margin: auto of the inner table

td {
  border: 1px solid blue;
  padding: 50px;  
}

.center {
  padding: 0;
}

/*Apply left and right margin: auto of the inner table*/
#main table {
  margin:auto;
}
<table id="main">
  <tr>
    <td>
      <table>
        <tr>
          <td></td>
          <td></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table>
        <tr>
          <td class="center">center me please</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table>
        <tr>
          <td></td>
          <td></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
vaishali kapadia
  • 934
  • 11
  • 22