如何将这个表格单元格放在一行中?

时间:2018-05-14 11:27:54

标签: css html-table html-email

我如何将单个细胞集中在tr内,是否有一种我不知道的属性?所以,我希望无论在上方还是下方添加多少个单元格,单个单元格都会居中,如果可能的话......?这是在电子邮件模板的上下文中。



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>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

只需将align="center"添加到您想要成为中心的table

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>

答案 1 :(得分:0)

简单应用内表的左右margin: auto

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>