我试图将TD中的某些文字垂直居中。我在头部的样式标记中尝试了valign: middle
行样式vertical-align: middle
。
我无法弄清楚为什么它会起作用,因为它似乎在我的桌面版上工作。下面是代码w / some 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>
答案 0 :(得分:0)
所以......我明白了!您需要使用容器上的show / hide类而不是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>