在表格内底部对齐

huangapple go评论65阅读模式
英文:

Bottom Align <td> within a table

问题

我正在尝试让按钮位于列的底部,并使文本顶部对齐。我尝试了多次,但下面我尝试了valign="bottom"和在中间列上使用vertical-align: bottom;的CSS,但没有成功。在包含每个列的主表上添加对齐会将表中的所有内容都移动到底部。感谢任何帮助!

<!-- 开始三列 -->
<tr>
    <td style="padding: 30px 0 40px 0;">
        <table width="100%" style="border-spacing:0;" role="presentation">
            <tr>
                <td class="three-columns" style="padding:0;font-size:0;text-align: center;">

                    <!--[if mso]>
                    <table width="100%" style="border-spacing:0;">
                        <tr>
                            <td width="200" valign="top" style="padding: 0;">
                    <![endif]-->

                    <table class="column" style="border-spacing:0;width: 100%;max-width: 200px;display: inline-block;vertical-align: top;" role="presentation">
                        <tr>
                            <td class="padding" style="padding:15px;">

                                <table class="content" style="border-spacing:0;text-align: center;" role="presentation">
                                    <tr>
                                        <td style="padding:10px 10px 20px 10px;">
                                            <p style="font-size: 15px;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum quisquam nostrum, reprehenderit consequatur odio sint sed, illo adipisci laudantium soluta animi tempora qui obcaecati maiores aut. Laboriosam esse expedita dolorum.</p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center">
                                            <table align="center" role="presentation" style="border-spacing:0;">
                                                <tr>
                                                    <td align="center" style="border-radius:10px;" bgcolor="#fff">
                                                        <a href="https://example.com/14" target="_blank" style="font-size: 15px;font-weight: bold;text-decoration: none;color: #000;background-color: #fff;padding:8px 20px;border: 1px solid #fff;border-radius: 10px;display: inline-block;">
                                                            Email Audience
                                                        </a>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>

                            </td>
                        </tr>
                    </table>

                    <!--[if mso]>
                    </td><td width="200" valign="top" style="padding: 0;">
                    <![endif]-->

                    <table class="column" style="border-spacing:0;width: 100%;max-width: 200px;display: inline-block;" role="presentation">
                        <tr>
                            <td class="padding" style="padding:15px;">

                                <table class="content" style="border-spacing:0;text-align: center;" role="presentation">
                                    <tr>
                                        <td style="padding:10px 10px 20px 10px;">
                                            <p style="font-size: 15px;">Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas explicabo iure praesentium obcaecati eaque? Quod, assumenda.</p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" style="vertical-align: bottom;">
                                            <table align="center" role="presentation" style="border-spacing:0; vertical-align: bottom;">
                                                <tr>
                                                    <td align="center" style="border-radius:10px;vertical-align: bottom;" bgcolor="#000" valign="bottom">
                                                        <a href="https://example.com/16" target="_blank" style="font-size: 15px;font-weight: bold;text-decoration: none;color: #ffffff;background-color: #000;padding:8px 20px;border: 1px solid #000;border-radius: 10px;display: inline-block;">
                                                            Second Button
                                                        </a>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>

                            </td>
                        </tr>
                    </table>

                    <!--[if mso]>
                    </td><td width="200" valign="top" style="padding: 0;">
                    <![endif]-->

                    <table class="column" style="border-spacing:0;width: 100%;max-width: 200px;display: inline-block;vertical-align: top;" role="presentation">
                        <tr>
                            <td class="padding" style="padding:15px;">

                                <table class="content" style="border-spacing:0;text-align: center;" role="presentation">
                                    <tr>
                                        <td style="padding:10px 10px 20px 10px;">
                                            <p style="font-size: 15px;">Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam ipsum aspernatur neque odit dolorem molestias consequatur enim consectetur dicta ab rem provident deserunt expedita, id quas doloremque illo dignissimos! Blanditiis!</p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center">
                                            <table align="center" role="presentation" style="border-spacing:0;">
                                                <tr>
                                                    <td align="center" style="border-radius:10px;" bgcolor="#fff">
                                                        <a href="https://example.com/18" target="_blank" style="font-size: 15px;font-weight: bold;text-decoration: none;color: #000;background-color: #fff;padding:8px 20px;border: 1px solid #fff;border-radius: 10px;display: inline-block;">
                                                            Third Button
                                                        </a>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>

                            </td>
                        </tr>
                    </table>

                    <!--[if mso]>
                    </td>
                    </tr>
                    </table>
                    <![endif]-->

                </td>
            </tr>
        </table>
    </td>
</tr>
<!-- 结束三列 -->
英文:

I'm trying to get the buttons to line up at the bottom of the columns with the text being top aligned. I've had a number of attempts, but below I've attempted valign="bottom" and the vertical-align:bottom; css on the middle column without success. Adding alignment to the main table containing each column (with the class table) will shift all content within the table to the bottom. Any help would be appreciate, thanks!

&lt;!-- START THREE COLUMNS --&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 30px 0 40px 0;&quot;&gt;
&lt;table width=&quot;100%&quot; style=&quot;border-spacing:0;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td class=&quot;three-columns&quot; style=&quot;padding:0;font-size:0;text-align: center;&quot;&gt;
&lt;!--[if mso]&gt;
&lt;table width=&quot;100%&quot; style=&quot;border-spacing:0;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td width=&quot;200&quot; valign=&quot;top&quot; style=&quot;padding: 0;&quot;&gt;
&lt;![endif]--&gt;
&lt;table class=&quot;column&quot; style=&quot;border-spacing:0;width: 100%;max-width: 200px;display: inline-block;vertical-align: top;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td class=&quot;padding&quot; style=&quot;padding:15px;&quot;&gt;
&lt;table class=&quot;content&quot; style=&quot;border-spacing:0;text-align: center;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;padding:10px 10px 20px 10px;&quot;&gt;
&lt;p style=&quot;font-size: 15px;&quot;&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum quisquam nostrum, reprehenderit consequatur odio sint sed, illo adipisci laudantium soluta animi tempora qui obcaecati maiores aut. Laboriosam esse expedita dolorum.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;center&quot;&gt;
&lt;table align=&quot;center&quot; role=&quot;presentation&quot; style=&quot;border-spacing:0;&quot;&gt;
&lt;tr&gt;
&lt;td align=&quot;center&quot; style=&quot;border-radius:10px;&quot; bgcolor=&quot;#fff&quot;&gt;
&lt;a href=&quot;https://example.com/14&quot; target=&quot;_blank&quot; style=&quot;font-size: 15px;font-weight: bold;text-decoration: none;color: #000;background-color: #fff;padding:8px 20px;border: 1px solid #fff;border-radius: 10px;display: inline-block;&quot;&gt;
Email Audience
&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;!--[if mso]&gt;
&lt;/td&gt;&lt;td width=&quot;200&quot; valign=&quot;top&quot; style=&quot;padding: 0;&quot;&gt;
&lt;![endif]--&gt;
&lt;table class=&quot;column&quot; style=&quot;border-spacing:0;width: 100%;max-width: 200px;display: inline-block;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td class=&quot;padding&quot; style=&quot;padding:15px;&quot;&gt;
&lt;table class=&quot;content&quot; style=&quot;border-spacing:0;text-align: center;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;padding:10px 10px 20px 10px;&quot;&gt;
&lt;p style=&quot;font-size: 15px;&quot;&gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas explicabo iure praesentium obcaecati eaque? Quod, assumenda.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;center&quot; style=&quot;vertical-align: bottom;&quot; valign=&quot;bottom&quot;&gt;
&lt;table align=&quot;center&quot; role=&quot;presentation&quot; style=&quot;border-spacing:0; vertical-align: bottom;&quot; valign=&quot;bottom&quot;&gt;
&lt;tr&gt;
&lt;td align=&quot;center&quot; style=&quot;border-radius:10px;vertical-align: bottom;&quot; bgcolor=&quot;#000&quot; valign=&quot;bottom&quot;&gt;
&lt;a href=&quot;https://example.com/16&quot; target=&quot;_blank&quot; style=&quot;font-size: 15px;font-weight: bold;text-decoration: none;color: #ffffff;background-color: #000;padding:8px 20px;border: 1px solid #000;border-radius: 10px;display: inline-block;&quot;&gt;
Second Button
&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;!--[if mso]&gt;
&lt;/td&gt;&lt;td width=&quot;200&quot; valign=&quot;top&quot; style=&quot;padding: 0;&quot;&gt;
&lt;![endif]--&gt;
&lt;table class=&quot;column&quot; style=&quot;border-spacing:0;width: 100%;max-width: 200px;display: inline-block;vertical-align: top;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td class=&quot;padding&quot; style=&quot;padding:15px;&quot;&gt;
&lt;table class=&quot;content&quot; style=&quot;border-spacing:0;text-align: center;&quot; role=&quot;presentation&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;padding:10px 10px 20px 10px;&quot;&gt;
&lt;p style=&quot;font-size: 15px;&quot;&gt;Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam ipsum aspernatur neque odit dolorem molestias consequatur enim consectetur dicta ab rem provident deserunt expedita, id quas doloremque illo dignissimos! Blanditiis!&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align=&quot;center&quot;&gt;
&lt;table align=&quot;center&quot; role=&quot;presentation&quot; style=&quot;border-spacing:0;&quot;&gt;
&lt;tr&gt;
&lt;td align=&quot;center&quot; style=&quot;border-radius:10px;&quot; bgcolor=&quot;#fff&quot;&gt;
&lt;a href=&quot;https://example.com/18&quot; target=&quot;_blank&quot; style=&quot;font-size: 15px;font-weight: bold;text-decoration: none;color: #000;background-color: #fff;padding:8px 20px;border: 1px solid #fff;border-radius: 10px;display: inline-block;&quot;&gt;
Third Button
&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;!--[if mso]&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;![endif]--&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;!-- END THREE COLUMNS --&gt;

答案1

得分: 1

为了实现响应式设计,电子邮件中创建三列的典型方法是将表格分开,就像您的工作中所示。因此,您不能使用vertical-align来匹配它们,因为每个表格不知道其他表格在做什么。

唯一的前进之路是手动添加空间,例如,对<td>添加内边距,例如:

<td align="center" style="padding-top:20px;border-radius:10px;" bgcolor="#000">

但然后您可能需要查看在移动设备上需要多少内边距,或者仅在桌面设备上添加此内边距。

我更喜欢采用移动优先的方法,因为不接受<style>块的移动设备比不接受<style>块的桌面设备更多。

您可以这样做:

<style>
  @media screen and (min-width:600px) {
    .desktopPadding { 
      padding-top: 20px!important;
    }
  }
</style>
<td align="center" class="desktopPadding" style="padding:0;border-radius:10px;mso-padding-alt: 20px 0 0 0;" bgcolor="#000">

请注意Outlook(Windows桌面版)的mso-padding-alt代码,因为它不接受@media查询。

或者,您可以使用其他间距方法,如<p style="margin:20px 0 0 0;line-height:0;font-size:0;">&nbsp;</p>

英文:

In order to achieve responsiveness, the typical way to do 3 columns in email is to separate the tables - as shown in your work. Therefore, you can't match them using vertical-align, since each table doesn't know what the other tables are doing.

The only way forward is to add space manually, e.g. add padding to the &lt;td&gt;, e.g.:

&lt;td align=&quot;center&quot; style=&quot;padding-top:20px;border-radius:10px;&quot; bgcolor=&quot;#000&quot;&gt;

But then you may need to look at what padding you need for mobile, or only add this padding for desktop.

I prefer a mobile-first approach, as there are more mobiles that don't accept &lt;style&gt; blocks than desktops that don't accept &lt;style&gt; blocks.

You can do this:

&lt;style&gt;
@media screen and (min-width:600px) {
.desktopPadding { 
padding-top: 20px!important;
}
}
&lt;/style&gt;
&lt;td align=&quot;center&quot; class=&quot;desktopPadding&quot; style=&quot;padding:0;border-radius:10px;mso-padding-alt: 20px 0 0 0;&quot; bgcolor=&quot;#000&quot;&gt;

Note the Outlook (Windows desktop) code mso-padding-alt, since it doesn't accept @media queries.

Alternatively, you can use other methods of spacing like &lt;p style=&quot;margin:20px 0 0 0;line-height:0;font-size:0;&quot;&gt;&amp;nbsp;&lt;/p&gt;

huangapple
  • 本文由 发表于 2023年7月27日 22:17:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780658.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定