如何在HTML电子邮件中的锚标记旁添加图标?

时间:2018-05-21 17:18:38

标签: html css anchor html-email

如何在锚标记<a>旁边设置图像(右侧的小箭头),并使它们在垂直和水平方向上保持对齐。我一直在尝试多种方式,但遇到了我尝试的每种方法的错误。要么<a>标记在html电子邮件中不起作用(不可点击),要么箭头位于可点击区域之外。我只需要以下代码之一。这是我尝试过的一些内容:

第一个代码:这里的问题是:如果用户点击箭头它不会响应,因为它不在<a>标记内,但这是有效的< / p>

&#13;
&#13;
<table cellpadding="0" cellspacing="0" border="0" width="33%" align="right" style="font-family: Arial, Helvetica, sans-serif; text-align: center;">
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#007cb0; font-weight: normal;text-align: center;">
        <tr>
          <td align="left" style="padding: 15px 0px 15px 30px; text-decoration: none; font-size: 11px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700;  vertical-align: top; line-height: normal !important;">
            <a style="font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer;">Go to Link</a>
          </td>
          <td align="right" style="text-align: left; color: #FFFFFF; font-weight: 700;"><img src="https://png.icons8.com/metro/50/ffffff/forward.png" width="15"></td>
          <td><img src="http://via.placeholder.com/5/007cb0" width="5" /></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
&#13;
&#13;
&#13;

第二段代码:我无法在<td>

内垂直对齐文字

&#13;
&#13;
<table cellpadding="0" cellspacing="0" border="0" width="33%" align="right" style="font-family: Arial, Helvetica, sans-serif; text-align: center;">
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#007cb0; font-weight: normal;text-align: center;">
        <tr>
          <td height="50" align="left" style="text-decoration: none; font-size: 11px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700;  vertical-align: top; line-height: 100% !important;">
            <a style="height:100%;font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer; display: block">Go to Link <img src="https://png.icons8.com/metro/50/ffffff/forward.png" width="20" style="vertical-align: middle;"></a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
&#13;
&#13;
&#13;

第三个代码这里的问题是:它无法在任何电子邮件客户端中工作,并且该链接无法点击。

&#13;
&#13;
<table class="mobile" cellpadding="0" cellspacing="0" border="0" width="33%" align="right" style="font-family: Arial, Helvetica, sans-serif;">
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#007cb0; font-weight: normal;">
        <tr>
          <td>
            <a style="border: 1px solid red; padding: 20px;display: block; font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer;">
              <table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer;">
                <tr style="font-size: 16px; text-align: left; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer;">
                  <td align="left" style="text-decoration: none; font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700;  vertical-align: top; line-height: normal !important;">
                    GET VERSATILE
                  </td>
                  <td align="right" style="text-align: center; color: #FFFFFF; font-weight: 700;"><img src="https://png.icons8.com/metro/50/ffffff/forward.png" width="15" /></td>
                </tr>
              </table>
            </a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
&#13;
&#13;
&#13;

摘要:

我需要此<a>标记旁边有一个箭头,并且可以在蓝色区域周围点击。

感谢您的帮助。

5 个答案:

答案 0 :(得分:2)

这适用于大多数电子邮件客户端,即使我更改了锚标记内的文本。

希望这会有所帮助。

<table class="mobile" cellpadding="0" cellspacing="0" border="0" width="33%" align="right" style="font-family: Arial, Helvetica, sans-serif;">
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#007cb0;font-family: Arial, Helvetica, sans-serif;font-weight: bold;">
        <tr>
          <td class="links" style="padding: 10px; color: #ffffff; vertical-align: middle; text-align: center; font-family: Arial, Helvetica, sans-serif;font-weight: bold;"><a style="text-align: center; display: block;cursor: pointer;font-family: Arial, Helvetica, sans-serif; color: #ffffff !important; text-decoration: none; font-size: 16px; line-height: 20px; font-weight: bold;" pm-link="landingpage1" pm-link-default-url="global_landingpage">GO TO LINK<img src="http://via.placeholder.com/15/007cb0" width="15" alt="" /><img src="https://png.icons8.com/metro/50/ffffff/forward.png" width="20" style="vertical-align: middle;padding: 0 0 4px 0;max-width: 20px" /></a></td>
        </tr>
      </table>
    </td>
  </tr>
</table>

答案 1 :(得分:1)

<强>被修改

现在我知道你正在制作一个与右边对齐的按钮,我有更好的方法。

<table role="presentation" cellspacing="0" cellpadding="0" border="0" align="right">
  <tr>
    <td><!-- The button code --> 
    <table role="presentation" cellspacing="0" cellpadding="0" border="0">
        <tr>
            <td style="background: #007cb0; text-align: center;">
              <a href="#" target="_blank" style="background: #007cb0; 
              border: 15px solid #007cb0; font-family: sans-serif; font-size: 16px; 
              line-height: 110%; text-align: center; text-decoration: none !important; 
              display: block; font-weight: 700;"><span style="color:#ffffff;">&nbsp;&nbsp;&nbsp;&nbsp;Go to Link&nbsp;<img src="https://png.icons8.com/metro/50/ffffff/forward.png" width="15">
              &nbsp;&nbsp;&nbsp;</span></a>
            </td>
        </tr>
    </table>
    </td>
  </tr>
</table>

此代码将在每个电子邮件客户端中正确对齐并显示。它在Outlook中看起来并不完美。为此,您需要专门为Outlook添加间隔表。

我正在删除较旧的帖子和代码,但老实说,这与我昨天发布的添加&nbsp;的内容相同,它为您提供了一种可靠的填充形式。

答案 2 :(得分:1)

不确定您是否考虑过这一点,但它应该像在第一个问题的图像周围添加a标记一样简单。

请尝试以下操作,看看它是否适合您。我刚从sdling td添加了你的标签,只是为了给你一个想法。

<table cellpadding="0" cellspacing="0" border="0" width="33%" align="right" style="font-family: Arial, Helvetica, sans-serif; text-align: center;">
  <tr>
    <td>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#007cb0; font-weight: normal;text-align: center;">
        <tr>
          <td align="left" style="padding: 15px 0px 15px 30px; text-decoration: none; font-size: 11px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700;  vertical-align: top; line-height: normal !important;">
            <a style="font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer;">Go to Link</a>
          </td>
          <td align="right" style="text-align: left; color: #FFFFFF; font-weight: 700;"><img src="https://png.icons8.com/metro/50/ffffff/forward.png" width="15"></td>
          <td><a style="font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer;"><img src="http://via.placeholder.com/5/007cb0" width="5" /></a></td>
        </tr>
      </table>
    </td>
  </tr>
</table>

希望这个答案适合你。

答案 3 :(得分:0)

你能说出为什么使用表格式来制作按钮式链接吗?这是特定的HTML电子邮件?这似乎更容易,并在一些自定义后将给出相同的外观:

&#13;
&#13;
a {
  display: inline-block;
  border: 1px solid black;
  padding: 10px;
}
&#13;
<a href="">Link <span> &#x276F;</span></a>
&#13;
&#13;
&#13;

答案 4 :(得分:-1)

确定然后只需添加/调整边距和填充以使可点击区域变大

a{
  display: inline-block;
  position: relative;
  z-index: 1;
  padding: 1em;
  margin: -1em;
}

td img{
  padding-bottom: 5px;
}

https://jsfiddle.net/33q09cy0/

并在标记引用中添加图像。

<td align="left" style="padding: 15px 0px 15px 30px; text-decoration: none; font-size: 11px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700;  vertical-align: top; line-height: normal !important;">
        <a style="font-size: 16px; text-align: center; font-family: arial, sans-serif; color: #FFFFFF; font-weight: 700; cursor: pointer;">Go to Link</a>
        <img src="https://png.icons8.com/metro/50/ffffff/forward.png" width="15">
</td>
相关问题