【发布时间】:2021-08-22 21:48:26
【问题描述】:
我使用HandlebarsJS 创建了一个简单的HTML 电子邮件模板。
我已将文本和表格设置为在电子邮件中居中。
但是表格元素在左侧居中但在右侧溢出到电子邮件的右侧边框。
当我在chrome 中打开 HTML 文件时,不会发生这种情况 - 仅在 Outlook 中。
如何在 Outlook 中避免这种情况?
与表格相关的 HTML:
<div class="table">
<table id="carTable" role="presentation" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<th>Car Number</th>
<th>Group</th>
</tr>
<!-- {{#each cars}} -->
<tr>
<td>{{carNumber}}</td>
<td>{{processGroup}}</td>
</tr>
<!--{{/each}} -->
</tbody>
</table>
</div>
与表格相关的 CSS:
<style>
#carTable tr, td, th {
padding: 10px;
font-family: Arial;
font-size: 13px;
font-weight: normal;
font-stretch: normal;
font-style: normal;
line-height: 1.38;
letter-spacing: normal;
color: #333333;
}
#carTable{
border: solid 1px #cccccc;
}
#carTable td,
th {
height: 30px;
transition: all 0.3s;
/* Simple transition for hover effect */
}
#carTable th {
background: #DFDFDF;
/* Darken header a bit */
font-weight: bold;
text-align: left
}
#carTable td {
background: #FAFAFA;
text-align: left
}
/* Cells in even rows (2,4,6...) are one color */
#carTable tr:nth-child(even) td {
background: #F1F1F1;
}
/* Cells in odd rows (1,3,5...) are another (excludes header cells) */
#carTable tr:nth-child(odd) td {
background: #FEFEFE;
}
#carTable tr>:nth-child(1):not(th){
font-weight: bold;
color: #2d89ac;
}
</style>
带有完整 HTML 代码的 CodePen 链接: https://codepen.io/Java123999/pen/zYGBoPe
问题的屏幕截图,注释表格与左侧的段落一致但不在右侧
【问题讨论】:
-
您能否在 Outlook 中发布您的最终代码输出和问题的屏幕截图以及它的外观,即它在 Chrome 中的外观?
-
我已经添加了问题的截图,如果你能看一下,谢谢
-
从屏幕截图中,看起来您的列的宽度正在尽可能地减少,但是随着您拥有的列数和字体大小,它们不能再减少了,所以表格越过电子邮件边缘。不过我只是猜测。如果您可以直接在答案中或在 Codepen 之类的服务中发布代码并提供链接,那么我们可以调试实际输出并查看发送时发生的情况。
-
这里是带有完整 HTML 代码的 codepen 链接:codepen.io/Java123999/pen/zYGBoPe
标签: html css html-table outlook handlebars.js