使用 JPG 图像作为边框的 HTML 表格
我正在尝试创建一个用于电子邮件活动的“证书”。 我们正在努力保持与 Outlook 2007 的兼容性,这限制了我们使用背景属性来仅加载单个图片以显示在文本后面。
我已将边框切成 4 块(左、上、右、下)并将它们放置在跨列和行中,但无法使它们正确对齐。 基于此代码有什么建议吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Special Offer from Toyota/Scion of Clifton Park</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
font-style: italic;
}
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style8 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: italic;
color: #666666;
}
.style9 {color: #666666}
.style10 {color: #000000}
}
-->
</style>
</head>
<body>
<table width="610" height="984" border="0" cellspacing="0" cellpadding="0">
<tr></tr>
<tr>
<td width="74" rowspan="11"><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/left_image2.jpg" alt="Left Image" width="70" height="984" align="top" /></td>
<td colspan="5"><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/top_image3.jpg" alt="Top Image" width="461" height="171" align="left" /></td>
<td width="87" rowspan="11"><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/right_image2.jpg" border=0 alt="Right Image" width="71" height="984" align="bottom" /></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="90"> </td>
<td width="90"> </td>
<td width="90"> </td>
<td width="91"> </td>
</tr>
<tr>
<td colspan="5"><div align="center">
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"><span class="style8"><br/>
</span><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/bottom_image2.jpg" alt="Bottom Image" width="466" height="63" align="top" /><br />
</p>
</div></td>
</tr>
</table>
</body>
</html>
I'm trying to create a "certificate" for use in an email capmaign. We are trying to maintain compatability with Outlook 2007 and that limits us from using the background property to just load a single picture to display behind the text.
I've chopped my borders up in 4 pieces (left, top, right, bottom) and placed them in spanned columns and rows but cannot get them to line up properly. Any suggestions based on this code?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Special Offer from Toyota/Scion of Clifton Park</title>
<style type="text/css">
<!--
.style1 {font-family: Arial, Helvetica, sans-serif}
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
font-style: italic;
}
.style4 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style8 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: italic;
color: #666666;
}
.style9 {color: #666666}
.style10 {color: #000000}
}
-->
</style>
</head>
<body>
<table width="610" height="984" border="0" cellspacing="0" cellpadding="0">
<tr></tr>
<tr>
<td width="74" rowspan="11"><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/left_image2.jpg" alt="Left Image" width="70" height="984" align="top" /></td>
<td colspan="5"><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/top_image3.jpg" alt="Top Image" width="461" height="171" align="left" /></td>
<td width="87" rowspan="11"><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/right_image2.jpg" border=0 alt="Right Image" width="71" height="984" align="bottom" /></td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td colspan="5"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="90"> </td>
<td width="90"> </td>
<td width="90"> </td>
<td width="91"> </td>
</tr>
<tr>
<td colspan="5"><div align="center">
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"> </p>
<p class="style4"><span class="style8"><br/>
</span><img src="http://pbrgraphics.com/Constant_Contact/TCP/cert_borders/bottom_image2.jpg" alt="Bottom Image" width="466" height="63" align="top" /><br />
</p>
</div></td>
</tr>
</table>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
感谢您的所有建议 - 非常有帮助! 如果你好奇的话,这就是我最终得到的结果。 在浏览器中预览错误,但在接收端的电子邮件客户端中显示正确。 我成功测试了 Gmail、Outlook 2000/2007、Yahoo(旧/新)、Hotmail、Thunderbird。
还在电子邮件中找到了 CSS 指南 http://www.campaignmonitor.com/css/
(如果发送到 Outlook 2007/2010 和 Gmail 客户端,则基本避免)
Thanks for all your suggestions - GREAT HELP! Here's what I ended up with if you are curious. Previews wrong in browsers, but displays correctly in email clients on the receiving end. I tested Gmail, Outlook 2000/2007, Yahoo (old/new), Hotmail, Thunderbird successfully.
Also found this guide to CSS in emails http://www.campaignmonitor.com/css/
(basically avoid it if sending to Outlook 2007/2010 and Gmail clients)
您可以通过将 valign="top" 和 valign="bottom" 添加到表格顶部和底部的中心单元格来完成此操作。
像这样:
You can do it by adding valign="top" and valign="bottom" to the center cells in the top and bottom for the table.
like so:
所有中间列单元格的高度都是可变的(不是固定的),因此浏览器只会尝试将它们调整到它认为最好的高度。
您需要使用 style 属性来修复它们的高度,如下所示:
这适用于包含顶部图像的单元格,因为图像的高度为 171px。
另外:中间需要9排吗? 或者你尝试过这样来定位边界吗?
编辑:或者Re0sless所说的。 ;D
All of your middle column cells have variable heights (not fixed) and so the browser will just try to adjust them to what it thinks is best.
You need to fix their heights by using the style attribute like so:
That would be for the cell containing the top image as the image has a height of 171px.
Also: Do you need 9 rows in the center? Or did you try that to position the borders?
Edit: Or what Re0sless said. ;D
...有几种方法可以修复它,其中一种(如果它可以在 Outlook 中工作并在所有其他邮件代理中显示)是将顶部和底部边框图像绝对定位在单元格中。
其次,我也许会重组表格。 使顶部和底部边框跨越所有列,就好像它们从顶部和底部覆盖表格并从那里取出它一样。
... there are couple of ways to fix it, one (if it will work in outlook and display in all other mail agents) would be to position the top and bottom border images absolutely in the cells.
Second, I'd restructure the table maybe. Make the top and bottom borders span all the columns, as if they were capping the table from top and bottom and take it from there.
我的建议:
My suggestions:
.... top_image3.jpg ....
2.
剪切一个新图像用于底部,其中包括整个表格的左、中、右列,并将其放入 colspan="7" 的单元格中
.... top_image3.jpg ....
2.
Cut a new image to use for the bottom which includes the left, middle, and right columns of the entire table and throw it in a cell with a colspan="7"
确保您重置所有CSS,以便在您之前将边距和填充设置为0应用任何样式。
Make sure you reset all your CSS so that margin and padding is at 0 before you apply any styles.
在围绕这个问题寻找我自己的“使用图像作为边框的 HTML 表格”的要求后,我找到了一个在其他地方没有看到的解决方案。 它在tbody、tr和td上使用单独的背景来达到预期的效果。 这是 IE8 (CSS2) 兼容的解决方案:
CSS3 中的解决方案是使用多个背景:
希望这对将来的人有帮助。
After hunting around on this question for my own requirements of "HTML Tables using images as borders" I came to a solution that I did not see elsewhere. It uses a separate background on the tbody, tr and td to achieve the desired effect. Here is the IE8 (CSS2) compatible solution:
The solution in CSS3 is to use multiple backgrounds:
Hope this helps someone in the future.