英文:
Extra whitespace under image in table - html email
问题
我有一个用于响应式电子邮件设计的模块,它在我的图像下方插入了一小部分空白,我无法弄清楚原因。似乎不管图像的比例或大小如何,始终都有相同数量的空间。
我内联了所有的CSS - 类声明仅用于@media查询。我已经向包含该图像的任何内容添加了padding-bottom: 0; border:0; border-collapse:collapse;
,但似乎没有任何方式能改变结果...
这是问题的屏幕截图。您可以看到她的照片下方有一小段空白。
<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;"> </i>
<![endif]-->
<span style="mso-text-raise: 15pt;">开始测验</span>
<!--[if mso]>
<i style="letter-spacing: 25px; mso-font-width: -100%;"> </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.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<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;">
How mindful are you?
</h2>
<p style="padding: 0 15% 10px 15%; font-family: 'Arial'; font-size: 10pt; line-height: 12pt; color: #63666a;">
See if your habits and attitudes are helping you be more present and purposeful.
</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;">Take the quiz</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>
<!-- 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
这是由于图像默认为内联元素所引起的。
您可以将图像更改为块级元素,<img style="display:block;" ... />
,或者,如果您希望仍然能够使图像居中,可以使用vertical-align:middle
:<img style="vertical-align:top;" ... />
(或者是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, <img style="display:block;" ... />
, or, if you wanted to be able to center the image still, use vertical-align:middle: <img style="vertical-align:top;" ... />
(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.
<p style="text-align:center;"><img style="vertical-align:top;" ... /></p>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论