电子邮件 HTML 边框在内容上,而不是在单元格上?
Email HTML border over content, not cell?
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="border:2px solid #ffffff; padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</td>
</tr>
</table>
无论我在哪里添加边框样式,它总是包裹整个单元格,而不是单元格 content 本身。
代码如下:
如果我将它添加到 span 元素上,它会完全打破边框,如下所示:
这是我需要的:
我做错了什么?
将边框放在 h3
上并使其成为 inline-block
td {
background: grey;
text-align: center;
}
h3 {
border: 1px solid white;
display: inline-block;
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</td>
</tr>
</table>
您的问题有多种解决方案:
一种是在您的单元格内容周围添加一个 div,如下所示:
table {background: black}
.contour {
border: 2px solid #ccc;
width: 50%;
height: 20%;
margin: 10px auto
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="border:2px solid #ffffff; padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<div class="contour">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</div>
</td>
</tr>
</table>
另一种方法是使用 a
元素作为文本周围的块
table {background:black}
a {
display:block;
border:2px solid #ccc;
width: 50%;
margin: 0 auto;
padding:10px;
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="border:2px solid #ffffff; padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<div class="contour">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</div>
</td>
</tr>
</table>
不要为 table 设置样式,为内容设置样式并简化标记:
<td>
<a alias="" conversion="false" data-linkto="https://" href="google.com"
style="display:inline-block;border:2px solid #ffffff; padding: 8px 10px;color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;" title="Book Appointment">
BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</a>
</td>
这非常简单,并且可以在所有电子邮件客户端上一致地工作。
单行文字:
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="" style="margin: auto;">
<tr>
<td style="text-align: center;">
<h3 style="margin: 0;"><a href="#" style="border: 2px solid #ffffff; font-family: sans-serif; font-weight: bold; font-size: 16px; line-height: 22px; text-decoration: none; padding: 20px 30px; color: #ff0000; display: block; letter-spacing: 2px;">Book An Appointment<br />To Visit Us Tomorrow</a></h3>
</td>
</tr>
</table>
两行文字:
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="260" style="margin: 0; border: 2px solid #ff0000;">
<tr>
<td style="background: #222222; border: 8px solid #222222; text-align: center;">
<div style="padding: 10px 15px;">
<a href="#" style="background: #222222; border: 1px solid #222222; font-family: sans-serif; font-weight: bold; font-size: 16px; line-height: 22px; text-decoration: none; color: #ffffff; display: block; letter-spacing: 2px; mso-line-height-alt: 22px;">Book An Appointment To Visit Us Tomorrow</a>
</div>
</td>
</tr>
</table>
除非您需要 <h3>
屏幕阅读器,否则我建议将其删除。
祝你好运。
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="border:2px solid #ffffff; padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</td>
</tr>
</table>
无论我在哪里添加边框样式,它总是包裹整个单元格,而不是单元格 content 本身。
代码如下:
如果我将它添加到 span 元素上,它会完全打破边框,如下所示:
这是我需要的:
我做错了什么?
将边框放在 h3
上并使其成为 inline-block
td {
background: grey;
text-align: center;
}
h3 {
border: 1px solid white;
display: inline-block;
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</td>
</tr>
</table>
您的问题有多种解决方案: 一种是在您的单元格内容周围添加一个 div,如下所示:
table {background: black}
.contour {
border: 2px solid #ccc;
width: 50%;
height: 20%;
margin: 10px auto
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="border:2px solid #ffffff; padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<div class="contour">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</div>
</td>
</tr>
</table>
另一种方法是使用 a
元素作为文本周围的块
table {background:black}
a {
display:block;
border:2px solid #ccc;
width: 50%;
margin: 0 auto;
padding:10px;
}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="border:2px solid #ffffff; padding: 8px 10px; border-radius: 0px; -moz-border-radius: 0px; -webkit-border-radius: 0px; text-decoration:none;">
<div class="contour">
<h3 style="color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;">
<a alias="" conversion="false" data-linkto="https://" href="google.com" style="color:#ffffff;text-decoration:none; " title="Book Appointment">
<span>BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</span></a>
</h3>
</div>
</td>
</tr>
</table>
不要为 table 设置样式,为内容设置样式并简化标记:
<td>
<a alias="" conversion="false" data-linkto="https://" href="google.com"
style="display:inline-block;border:2px solid #ffffff; padding: 8px 10px;color:#FFFFFF;font-family:Arial, Helvetica, sans-serif;font-size:16px;font-style:normal;font-weight:bold;line-height:150%;letter-spacing:2px;text-decoration:none;text-align:center;" title="Book Appointment">
BOOK AN APPOINTMENT<br>
TO VISIT US TOMORROW</a>
</td>
这非常简单,并且可以在所有电子邮件客户端上一致地工作。
单行文字:
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="" style="margin: auto;">
<tr>
<td style="text-align: center;">
<h3 style="margin: 0;"><a href="#" style="border: 2px solid #ffffff; font-family: sans-serif; font-weight: bold; font-size: 16px; line-height: 22px; text-decoration: none; padding: 20px 30px; color: #ff0000; display: block; letter-spacing: 2px;">Book An Appointment<br />To Visit Us Tomorrow</a></h3>
</td>
</tr>
</table>
两行文字:
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="260" style="margin: 0; border: 2px solid #ff0000;">
<tr>
<td style="background: #222222; border: 8px solid #222222; text-align: center;">
<div style="padding: 10px 15px;">
<a href="#" style="background: #222222; border: 1px solid #222222; font-family: sans-serif; font-weight: bold; font-size: 16px; line-height: 22px; text-decoration: none; color: #ffffff; display: block; letter-spacing: 2px; mso-line-height-alt: 22px;">Book An Appointment To Visit Us Tomorrow</a>
</div>
</td>
</tr>
</table>
除非您需要 <h3>
屏幕阅读器,否则我建议将其删除。
祝你好运。