在HTML电子邮件中垂直中心文字



我正在尝试在TD中垂直居中一些文本。我已经尝试了在线样式的valign: middle,在头部样式标签中使用了vertical-align: middle

我无法弄清楚为什么它不起作用,因为它似乎在我的桌面版本上工作。以下是一些CSS和HTML段的代码。这将在手机中渲染,因此我的重点是Android和iPhone。

 @media screen and (min-width: 481px){
  .hideOnDesktop{display: none !important;
    }
  }
  @media screen and (max-width: 480px){
    .iosMiddle{vertical-align: middle;}
    .hideMobile{display: none !important;}
    .showMobile{display: block !important;}

<tr>
  <td>
    <table bgcolor="#ed1848" border="0" cellspacing="0" cellpadding="0" width="100%" height="121">
      <tr>
        <td width="112" border="0" cellspacing="0" cellpadding="0" valign="middle" style="border-collapse:collapse;"><img src="images/image.jpg"  width="112" height="121" alt="" style="display: block;width: 112px; height:auto;" border="0" ></td>
       <td class="hideMobile" width="247" height="121"  valign="middle" bgcolor="#ed1848" style="text-align: left; font-size: 30px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; font-weight: bold; -webkit-text-size-adjust: none; mso-line-height-rule: exactly;">Thanks for <br>your interest.</td>
<!--[if !mso 9]><!-->
       <td class="showMobile hideOnDesktop iosMiddle" width="247" height="121" valign="middle" bgcolor="#ed1848" style="display: none; text-align: left; font-size: 20px;  font-family: Helvetica, Arial, sans-serif; color: #ffffff; font-weight: bold; white-space: nowrap">Thanks for your interest.</td>
<!--<![endif]-->
      </tr>
    </table>
  </td>
</tr>

所以...我想出了!您需要在容器上使用表演/隐藏类,而不是在TD上使用以使垂直中心工作。

<tr>
  <td>
    <table class="hideMobile" bgcolor="#ed1848" border="0" cellspacing="0" cellpadding="0" width="100%" height="121">
      <tr>
        <td width="112" border="0" cellspacing="0" cellpadding="0" valign="middle" style="border-collapse:collapse;"><img src="image.jpg"  width="112" height="121" alt="" style="display: block;width: 112px; height:auto;" border="0" ></td>
        <td class="hideMobile" width="247" height="121"  valign="middle" bgcolor="#ed1848" style="text-align: left; font-size: 30px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; font-weight: bold; -webkit-text-size-adjust: none; mso-line-height-rule: exactly;">Thanks for <br>your interest.</td>
      </tr>
    </table>
<!--[if !mso 9]><!-->
<table class="showMobile hideOnDesktop" bgcolor="#ed1848" border="0" cellspacing="0" cellpadding="0" width="100%" height="121" style="display: none;">
  <tr>
    <td width="112" border="0" cellspacing="0" cellpadding="0" valign="middle" style="border-collapse:collapse;"><img src="image.jpg"  width="112" height="121" alt="" style="display: block;width: 112px; height:auto;" border="0" ></td>

        <td border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#ed1848" align="center" valign="middle" style="color: #ffffff; font-family:Arial, Helvetica, sans-serif; font-weight: bold; font-size: 20px; mso-line-height-rule: exactly; white-space: nowrap;">Thanks for your interest.</td>
      </tr>
    </table>
    <!--<![endif]-->
  </td>
</tr>

最新更新