HTML电子邮件:顶部和底部对齐的内容

chi*_*eek 5 html css email vertical-alignment html-email

问题

我正在处理包含项目列表的HTML电子邮件,并且考虑到电子邮件客户端的限制,我想知道以下设计是否可行。

项目清单

目前,我为每个项目都有一个表格,其中包含两个单元格(我们将其称为item-table)。第一个单元格(info-cell)的高度可变,包含商品信息和链接。第二个单元格(image-cell)包含图像,并且高度也可变。这个问题与第一个单元格有关。

我有一个嵌套info-cell有两行的表,每行有一个单元格。我们将这些单元格称为info-cell-topinfo-cell-bottom

理想的结果

期望的结果是info-cell-top与的顶部对齐,并与info-cell-bottom的底部对齐info-cell,而与的高度无关item-table

项目清单-笔记

我尝试过的

由于这是标记的电子邮件,我不能使用rowspan="2"image-cell解决这个问题。虽然它适用于某些桌面电子邮件客户端,但对于移动客户端,图像单元将完全消失。

我还尝试了info-cell同时使用height="100%"和将内部表拉伸到最大高度height="1"

这两种解决方案在浏览器中看起来都不错,但不适用于电子邮件。

代码

也可以在jsfiddle上玩。

<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border-top: 1px solid #bbbbbb;">
    <tbody>
        <tr>
            <td style="padding: 16px 0px; border-bottom: 1px solid #bbbbbb;">
                <table cellspacing="0" cellpadding="0" border="0" width="100%" height="1">
                    <tbody>
                        <tr>
                            <td style="vertical-align: top;">
                                <table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">
                                    <tbody>
                                        <tr>
                                            <td style="vertical-align: top;">
                                                <strong><a href="#" style="color: #000000; text-decoration: none;">Top aligned</a></strong>

                                                <br>Price
                                                <br>Size
                                                <br>
                                                <br>Wishlist comment - Phasellus sollicitudin consequat consectetur. Morbi a elit leo. Aliquam velit nibh, aliquet quis posuere at, vestibulum nec orci.
                                            </td>
                                        </tr>
                                        <tr>
                                            <td style="vertical-align: bottom;">
                                                <br>
                                                <br> <strong><a href="#" style="color: #000000; text-decoration: none;">Bottom aligned</a>
                                        &nbsp;&nbsp;&nbsp;<a href="#" style="color: #000000; text-decoration: none;">Add to cart</a>
                                        </strong>

                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                            <td width="120px" valign="bottom" style="padding-left: 16px;">
                                <div style="text-align: center; background: #ddd; height: 200px;padding: 30px 10px;box-sizing: border-box;"><b>Image with variable height</b>
                                    <br>
                                    <br>(may be shorter than left column)
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

认罪

对我可以做些什么来达到期望的结果有什么建议吗?你能帮我吗?

Joh*_*ohn 5

换出你的CSSvertical-align:top;的TD是这个:<td valign="top">

valign接受 top|middle|bottom 值,而align(horizo​​ntal) 接受 left|center|right。

对于此布局,您还需要 rowspan 或固定高度,因为嵌套表格(您的 2 行文本)不会推到容器单元格的最大高度。

以下是同时应用 valign 和 rowspan 的基本示例:

<table width="600" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="400" height="200" valign="top" bgcolor="#EEEEEE">Align Top
    </td>
    <td width="200" rowspan="2" valign="middle" bgcolor="#777777">
      <img alt="image" src="" width="200" height="300" style="margin: 0; border: 0; padding: 0; display: block;">
    </td>
  </tr>
  <tr>
    <td width="400" height="300" valign="bottom" bgcolor="#CCCCCC">Align Bottom
    </td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

它有助于在行跨单元格上设置高度,因为 Outlook 有时会猜测并弄乱行跨断点。关于这里的更多信息(虽然它指的是 colspan,但同样适用)