2013-10-28 930 views
1

我对HTML表格和内联CSS没有太多的经验,但我正在尝试创建一个HTML电子邮件签名。理想情况下,我想在左侧有一个小图像,中间有文字,右侧有一个较大的标识,一行文字位于一切下方。html表格和内联样式

我有基本的内容,但是我试图对齐所有与似乎没有工作的花车。什么是一切排列顺序的最佳方式?

jsfiddle

<br /> 
<meta name="format-detection" content="telephone=no"> 
<table width='600' id="sig" cellspacing='0' cellpadding='0' border-spacing='0' style="margin:0;padding:0;"> 
<tr> 
<td width="47" style="float:left;width:47px;margin:0;padding:0;"> 
<a href='http://example.com' style="border:none;text-decoration:none;"><img src="http://lorempixel.com/47/43/" alt="First Last" style="border:none;width:47px;"></a> 
</td> 

<td width="10" style="width:10px;">&nbsp;</td> 

<td valign='top' style="margin:0;padding:0;"> 
<table id="sig2" cellspacing='0' cellpadding='0' border-spacing='0' style="float:left;padding:0;margin:0;font-family:'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;font-size:13px;color:#D31145;border-collapse:collapse;-webkit-text-size-adjust:none;"> 
<tr style="margin:0;padding:0;color:#000104;"> 
<td style="margin:0;padding-left:8px;font-family:'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;font-size:16px;white-space:nowrap;"><a style="border:none;text-decoration:none;color:#D31145;" href="mailto:[email protected]">FIRST LAST</a> 
</td> 
</tr> 

<tr style="margin:0;padding:0;color:#000104;"> 
<td style="margin:0;padding-left:8px;font-family:'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;font-size:16px;white-space:nowrap;"> 
<span style="border:none;text-decoration:none;color:#000104;">REALTOR | P <a style="border:none;text-decoration:none;color:#000104;" href="tel:1111111111">111.111.1111</a></span> 
</td> 
</tr> 

<td width="177" style="float:right;width:177px;margin:0;padding:0;"> 
<a href='http://example.com' style="border:none;text-decoration:none;"><img src="http://lorempixel.com/177/54/" alt="ZOPA Realty Group" style="border:none;width:177px;"></a> 
</td> 
</table> 

<table width='600' id="sig" cellspacing='0' cellpadding='0' border-spacing='0' style="margin:-15 0 0 60;padding:0;"> 
<tr> 
<td><span style="margin:0;padding-left:8px;font-size:7px;font-family:'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;color:#000104;white-space:nowrap;">BRE xxxxxxxx | Broker BRE xxxxxxxx. In association with Keller Williams. Each Keller Williams Realty office is independently owned and operated.</span></td> 

<br /> 
&nbsp; 

example

回答

3

忘记浮动,保证金和HTML 3/5。邮件已经过时了。你需要用桌子做所有事情。 一行=一张表。你需要保证金或填充?做另一列。

Codepen

实施例:我需要 文本的 图片的40×40 2一个余量的10像素1一个3一个400像素

我开始行一个行:

<table style=" background-repeat:no-repeat; width:450px;margin:0;" cellpadding="0" cellspacing="0" border="0"> 
    <tr style="height:40px; width:450px; margin:0;"> 
    <td style="height:40px; width:40px; margin:0;"> 
     <img src="" style="width=40px;height40;margin:0;display:block" 
    </td> 
    <td style="height:40px; width:10px; margin:0;">   
    </td> 
    <td style="height:40px; width:400px; margin:0;"> 
    <p style=" margin:0;"> my text </p> 
    </td> 
    </tr> 
</table> 
+0

请您澄清一下吗? – AMC

+1

如果您使用浮动或位置。你将在webmail(gmail,yahoo等)上获得不错的结果,但outlook自2007年以来拥有相同的html阅读器。他只是了解表格。不要忘记重置保证金。祝你今天愉快 ! – ColoO

+0

你说的话很有道理,但是即使在你的例子Codepen中,问题仍然存在。当它应该水平排列时,较大的图像位于底部。 – AMC

3

这应该是绝招:

<table width="400" border="0" cellpadding="0" cellspacing="0"> 
    <tr> 
    <td width="50" height="40" valign="top" rowspan="3"> 
     <img alt="" src="" width="40" height="40" style="margin: 0; border: 0; padding: 0; display: block;"> 
    </td> 
    <td width="350" height="40" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #000000;"> 
<a href="" style="color: #D31145; font-weight: bold; text-decoration: none;">LAST FIRST</a><br> 
REALTOR | P 123.456.789 
    </td> 
    </tr> 
    <tr> 
    <td width="350" height="70" valign="bottom" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #000000;"> 
<img alt="" src="" width="200" height="60" style="margin: 0; border: 0; padding: 0; display: block;"> 
    </td> 
    </tr> 
    <tr> 
    <td width="350" height="20" valign="bottom" style="font-family: Helvetica, Arial, sans-serif; font-size: 10px; color: #000000;"> 
all your minor text here | all your minor text here | all your minor text here 
    </td> 
    </tr> 
</table> 

UPDATE:按照意见调整代码:

查看您的jsfiddle后,要注意有关表的一个重要的事情是其他每个一行表格单元格的宽度都必须是相同的宽度为第一,并且所有单元格都必须添加到表格的总宽度中。

这里是行不通的例子:

<table width="600" border="0" cellpadding="0" cellspacing="0"> 
    <tr> 
    <td width="200" bgcolor="#252525">&nbsp; 
    </td> 
    <td width="400" bgcolor="#454545">&nbsp; 
    </td> 
    </tr> 
    <tr> 
    <td width="300" bgcolor="#252525">&nbsp; 
    </td> 
    <td width="300" bgcolor="#454545">&nbsp; 
    </td> 
    </tr> 
</table> 

虽然第二排也加起来600,它(以及任何其他行)必须具有相同的200-400分的第一行,除非你正在使用colspans。如果您使用的是合并单元格,你可以有一列,但它需要具有相同的宽度,因为它是跨越细胞,所以此工程:

<table width="600" border="0" cellpadding="0" cellspacing="0"> 
    <tr> 
    <td width="200" bgcolor="#252525">&nbsp; 
    </td> 
    <td width="400" bgcolor="#454545">&nbsp; 
    </td> 
    </tr> 
    <tr> 
    <td width="600" colspan="2" bgcolor="#353535">&nbsp; 
    </td> 
    </tr> 
</table> 

不是一个完整的教程,但我希望帮助引导你朝着未来的正确方向发展。

这里是你所追求的代码:

<table width="900" border="0" cellpadding="0" cellspacing="0"> 
    <tr> 
    <td width="57" height="43" valign="top" rowspan="2"> 
     <img alt="Rashel Adragna" src="http://zoparealtygroup.com/wp-content/uploads/2013/10/sig_head.png" width="47" height="43" style="margin: 0; border: 0; padding: 0; display: block;"> 
    </td> 
    <td width="843" height="43" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #000000;"> 
<a href="" style="color: #D31145; font-weight: bold; text-decoration: none;">RASHEL ADRAGNA</a><br> 
REALTOR | P 855.900.24KW 
    </td> 
    </tr> 
    <tr> 
    <td width="843" height="64" valign="bottom" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #000000;"> 
<img alt="Zopa Realty Group logo" src="http://zoparealtygroup.com/wp-content/uploads/2013/10/sig_logo.png" width="177" height="54" style="margin: 0; border: 0; padding: 0; display: block;"> 
    </td> 
    </tr> 
    <tr> 
    <td width="843" colspan="2" height="20" valign="bottom" align="center" style="font-family: Helvetica, Arial, sans-serif; font-size: 10px; color: #000000;"> 
all your minor text here | all your minor text here | all your minor text here 
    </td> 
    </tr> 
</table> 

你会注意到,我增加了一个额外10px的一些表格单元格。这与align/valigns结合充当您的单元格之间的填充。这是一个聪明的方法,实际上不得不添加填充,边距或空填充单元。

+0

插入我自己的图片/值后,我遇到了和以前一样的问题http://jsfiddle.net/A3d9b/ – AMC

+0

这是什么问题?路线?截图可能会有所帮助。 – John

+0

查看我的原始问题,了解我如何使用它的模型 - 水平方向的所有内容,其中一行文本位于下方。 – AMC