[英]Vertically center text in HTML email
我正在嘗試將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本身上使用show / hide類,以使垂直中心起作用。
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.