Extra whitespace under image in table – html email

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

Extra whitespace under image in table - html email

问题

我有一个用于响应式电子邮件设计的模块,它在我的图像下方插入了一小部分空白,我无法弄清楚原因。似乎不管图像的比例或大小如何,始终都有相同数量的空间。

我内联了所有的CSS - 类声明仅用于@media查询。我已经向包含该图像的任何内容添加了padding-bottom: 0; border:0; border-collapse:collapse;,但似乎没有任何方式能改变结果...

这是问题的屏幕截图。您可以看到她的照片下方有一小段空白。

Extra whitespace under image in table – html email

<table style="background-color:grey">
  <tr>
    <td style="padding-left: 25px; padding-right:25px; padding:bottom:0px!important; border:0!impotant;">
      <table class="oneup50" align="center" valign="middle" style="width: 100%; vertical-align: middle; background-color: #FFFFFF; border:0; padding-bottom: 0; border-collapse: collapse!important;" role="presentation" dir="ltr">
        <tr>
          <td class="stackB" style="padding-bottom:0!important; display: inline-block!important; border:0!important; border-collapse:collapse!important;">
            <table>
              <tr>
                <td style="padding: 0;">
                  <a href="URL"><img width="287" class="imgStack" style="border: 0;" src="https://i.imgur.com/I1d9YPY.png"></a>
                </td>
              </tr>
            </table>
          </td>
          <td class="stack" valign="middle" align="center" width="263" style="height:219px; border:0; padding-bottom: 0; display: inline-block; vertical-align: middle!important;">
            <table role="presentation" valign="middle" style="border: 0; vertical-align: middle; display:inline-block;">
              <tr>
                <td valign="middle" style="width:47%; vertical-align: middle; padding:0;" height="218">
                  <table style="display:inline-block;">
                    <tr>
                      <td style="padding: 0;">
                        <center>
                          <h2 style="padding: 0 15% 0 15%; margin:0; font-family: 'Arial'; font-size: 12pt; color: #002855; line-height: 14pt; font-weight: bold; text-align: middle;">
                            你有多在意?
                          </h2>
                          <p style="padding: 0 15% 10px 15%; font-family: 'Arial'; font-size: 10pt; line-height: 12pt; color: #63666a;">
                            看看你的习惯和态度是否有助于你更加当下和有目标地生活。
                          </p>
                          <a class="button" rel="noopener" target="_blank" href="URL" style="background-color: #1a7ead; font-size: 12px; font-family: Helvetica, Arial, sans-serif; font-weight: bold; text-decoration: none; padding: 14px 40px; color: #ffffff; display: inline-block; mso-padding-alt: 0;">
                            <!--[if mso]>
                            <i style="letter-spacing: 25px; mso-font-width: -100%; mso-text-raise: 30pt;">&nbsp;</i>
                            <![endif]-->
                            <span style="mso-text-raise: 15pt;">开始测验</span>
                            <!--[if mso]>
                            <i style="letter-spacing: 25px; mso-font-width: -100%;">&nbsp;</i>
                            <![endif]-->
                          </a>
                        </center>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
英文:

I have this module for a responsive email design that inserts a little tiny amount of whitespace below my images and I can't figure out why. It doesn't seem to matter what the proportions or size of the image are. Always the same amount of space.

I inlined all of my CSS - the class declarations are only for @media queries. I've added padding-bottom: 0; border:0; border-collapse:collapse; to anything I could think of that contains that image in some way, nothing seems to even change the result in any way...

Here's a screenshot of the problem. You can see the small whitespace below her photo.

Extra whitespace under image in table – html email

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;table style=&quot;background-color:grey&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;padding-left: 25px; padding-right:25px; padding:bottom:0px!important; border:0!impotant;&quot;&gt;
&lt;table class=&quot;oneup50&quot; align=&quot;center&quot; valign=&quot;middle&quot; style=&quot;width: 100%; vertical-align: middle; background-color: #FFFFFF; border:0; padding-bottom: 0; border-collapse: collapse!important;&quot; role=&quot;presentation&quot; dir=&quot;ltr&quot;&gt;
&lt;tr&gt;
&lt;td class=&quot;stackB&quot; style=&quot;padding-bottom:0!important; display: inline-block!important; border:0!important; border-collapse:collapse!important;&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 0;&quot;&gt;
&lt;a href=&quot;URL&quot;&gt;&lt;img width=&quot;287&quot; class=&quot;imgStack&quot; style=&quot;border: 0;&quot; src=&quot;https://i.imgur.com/I1d9YPY.png&quot;&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td class=&quot;stack&quot; valign=&quot;middle&quot; align=&quot;center&quot; width=&quot;263&quot; style=&quot;height:219px; border:0; padding-bottom: 0; display: inline-block; vertical-align: middle!important;&quot;&gt;
&lt;table role=&quot;presentation&quot; valign=&quot;middle&quot; style=&quot;border: 0; vertical-align: middle; display:inline-block;&quot;&gt;
&lt;tr&gt;
&lt;td valign=&quot;middle&quot; style=&quot;width:47%; vertical-align: middle; padding:0;&quot; height=&quot;218&quot;&gt;
&lt;table style=&quot;display:inline-block;&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;padding: 0;&quot;&gt;
&lt;center&gt;
&lt;h2 style=&quot;padding: 0 15% 0 15%; margin:0; font-family: &#39;Arial&#39;; font-size: 12pt; color: #002855; line-height: 14pt; font-weight: bold; text-align: middle;&quot;&gt;
How mindful are you?
&lt;/h2&gt;
&lt;p style=&quot;padding: 0 15% 10px 15%; font-family: &#39;Arial&#39;; font-size: 10pt; line-height: 12pt; color: #63666a;&quot;&gt;
See if your habits and attitudes are helping you be more present and purposeful.
&lt;/p&gt;
&lt;a class=&quot;button&quot; rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;URL&quot; style=&quot;background-color: #1a7ead; font-size: 12px; font-family: Helvetica, Arial, sans-serif; font-weight: bold; text-decoration: none; padding: 14px 40px; color: #ffffff; display: inline-block; mso-padding-alt: 0;&quot;&gt;
&lt;!--[if mso]&gt;
&lt;i style=&quot;letter-spacing: 25px; mso-font-width: -100%; mso-text-raise: 30pt;&quot;&gt;&amp;nbsp;&lt;/i&gt;
&lt;![endif]--&gt;
&lt;span style=&quot;mso-text-raise: 15pt;&quot;&gt;Take the quiz&lt;/span&gt;
&lt;!--[if mso]&gt;
&lt;i style=&quot;letter-spacing: 25px; mso-font-width: -100%;&quot;&gt;&amp;nbsp;&lt;/i&gt;
&lt;![endif]--&gt;
&lt;/a&gt;
&lt;/center&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;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

<!-- end snippet -->

答案1

得分: 1

我通过这篇帖子找到了答案:https://stackoverflow.com/questions/5804256/image-inside-div-has-extra-space-below-the-image?rq=2

将图片本身设置为display: block解决了问题!

英文:

I figured it out thanks to this post: https://stackoverflow.com/questions/5804256/image-inside-div-has-extra-space-below-the-image?rq=2

Setting the image ITSELF to display: block fixed it!

答案2

得分: 0

这是由于图像默认为内联元素所引起的。

您可以将图像更改为块级元素,&lt;img style=&quot;display:block;&quot; ... /&gt;,或者,如果您希望仍然能够使图像居中,可以使用vertical-align:middle&lt;img style=&quot;vertical-align:top;&quot; ... /&gt;(或者是middle、bottom - 实际上并不重要)。

这将允许您在移动屏幕上保持图像居中,同时在桌面上将其左对齐。

<p style="text-align:center;"><img style="vertical-align:top;" ... /></p>

英文:

This is caused by the fact that an image is an inline element by default.

You can change the image to block, &lt;img style=&quot;display:block;&quot; ... /&gt;, or, if you wanted to be able to center the image still, use vertical-align:middle: &lt;img style=&quot;vertical-align:top;&quot; ... /&gt; (or middle, or bottom - it actually doesn't matter).

That would allow you to, for example, keep your image centered on mobile screens, while still having it left aligned on desktop.

&lt;p style=&quot;text-align:center;&quot;&gt;&lt;img style=&quot;vertical-align:top;&quot; ... /&gt;&lt;/p&gt;

huangapple
  • 本文由 发表于 2023年5月18日 01:57:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274958.html
匿名

发表评论

匿名网友

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

确定