HTML 电子邮件 <tr> 标签边框格式问题
HTML email <tr> tag border formatting issue
我正在尝试格式化 table 以使用 lines.Even 分隔行 尝试使用内联样式但没有任何效果。我在这里错过了什么吗?
预期输出:
我得到的输出:
这是我用来为电子邮件生成 HTML 的 perl 代码:
my $section_html = '';
$section_html.=qq(<table><tr style="border : 1px solid black;"><td>Hello1</td><td>Hello2</td></tr><tr style="border : 1px solid black;"><td>Hello3</td><td>Hello4</td></tr></table>);
my $email_html = <<EOF;
<html><head><style type="text/css">
body, td, th, strong { font-family: Verdana; font-size: 11px; }
table {
border:none;
border-collapse: collapse;
text-align:center;
}
table td {
border-left: 1px solid #000;
border-right: 1px solid #000;
}
table th {
border-left: 1px solid #000;
border-right: 1px solid #000;
}
table td:first-child {
border-left: none;
text-align:left;
}
table td:last-child {
border-right: none;
}
table tr{
border-top : 1px solid #000;
}
table tr{
border-top : 1px solid black;
}
</style></head>
<body bgcolor="#ffffff">
<span style="font-size: 20px">Report Header</span>$section_html</body></html>
EOF
# Write to file
open(FILE, ">/var/weekly_report/"."report"."_"."testing".".html") or die "Unable to open file for writing: $!\n";
print FILE $email_html;
close(FILE);
# Email weekly report
my $msg = MIME::Lite->new(
To => 'XXXX@somedomain.com',
Subject => 'Report subject',
Type => 'text/html',
Data => $email_html);
$msg->send();
一些电子邮件客户端(可能还有浏览器)不允许我们直接设置 <tr>
标签的样式。避免依赖 :first-child
和 :last-child
伪选择器也更安全,因为它们是 not well supported in email.
但是,我们可以通过设置 <table>
和 <td>
标签的样式来达到您想要的效果:
table {
border-top: 1px solid #000;
border-right: 1px solid #000;
}
table td,
table th {
border-left: 1px solid #000;
border-bottom: 1px solid #000;
}
您还可以通过内联所有 CSS 来拥有绝对控制权,这在 HTML 电子邮件中仍然是个好主意。
这是老派了。也试试这个方法。与 Ted 的答案不同的是,你有整个 table 相同的颜色,在他的答案中你可以选择不同的 td's
或 th's
.
的边框颜色
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#000000">
<tbody>
<tr>
<td width="50%" bgcolor="#ffffff">Hello1</td>
<td width="50%" bgcolor="#ffffff">Hello1</td>
</tr>
<tr>
<td bgcolor="#ffffff">Hello1</td>
<td bgcolor="#ffffff">Hello1</td>
</tr>
</tbody>
</table>
我正在尝试格式化 table 以使用 lines.Even 分隔行 尝试使用内联样式但没有任何效果。我在这里错过了什么吗?
预期输出:
我得到的输出:
这是我用来为电子邮件生成 HTML 的 perl 代码:
my $section_html = '';
$section_html.=qq(<table><tr style="border : 1px solid black;"><td>Hello1</td><td>Hello2</td></tr><tr style="border : 1px solid black;"><td>Hello3</td><td>Hello4</td></tr></table>);
my $email_html = <<EOF;
<html><head><style type="text/css">
body, td, th, strong { font-family: Verdana; font-size: 11px; }
table {
border:none;
border-collapse: collapse;
text-align:center;
}
table td {
border-left: 1px solid #000;
border-right: 1px solid #000;
}
table th {
border-left: 1px solid #000;
border-right: 1px solid #000;
}
table td:first-child {
border-left: none;
text-align:left;
}
table td:last-child {
border-right: none;
}
table tr{
border-top : 1px solid #000;
}
table tr{
border-top : 1px solid black;
}
</style></head>
<body bgcolor="#ffffff">
<span style="font-size: 20px">Report Header</span>$section_html</body></html>
EOF
# Write to file
open(FILE, ">/var/weekly_report/"."report"."_"."testing".".html") or die "Unable to open file for writing: $!\n";
print FILE $email_html;
close(FILE);
# Email weekly report
my $msg = MIME::Lite->new(
To => 'XXXX@somedomain.com',
Subject => 'Report subject',
Type => 'text/html',
Data => $email_html);
$msg->send();
一些电子邮件客户端(可能还有浏览器)不允许我们直接设置 <tr>
标签的样式。避免依赖 :first-child
和 :last-child
伪选择器也更安全,因为它们是 not well supported in email.
但是,我们可以通过设置 <table>
和 <td>
标签的样式来达到您想要的效果:
table {
border-top: 1px solid #000;
border-right: 1px solid #000;
}
table td,
table th {
border-left: 1px solid #000;
border-bottom: 1px solid #000;
}
您还可以通过内联所有 CSS 来拥有绝对控制权,这在 HTML 电子邮件中仍然是个好主意。
这是老派了。也试试这个方法。与 Ted 的答案不同的是,你有整个 table 相同的颜色,在他的答案中你可以选择不同的 td's
或 th's
.
<table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#000000">
<tbody>
<tr>
<td width="50%" bgcolor="#ffffff">Hello1</td>
<td width="50%" bgcolor="#ffffff">Hello1</td>
</tr>
<tr>
<td bgcolor="#ffffff">Hello1</td>
<td bgcolor="#ffffff">Hello1</td>
</tr>
</tbody>
</table>