Issue in creating email teamplate

前端 未结 3 1259
礼貌的吻别
礼貌的吻别 2021-01-24 16:18

I am trying to create an email template like following. I have used table. I am able to do everything except the image is not displayed at proper position. The images should be

相关标签:
3条回答
  • 2021-01-24 16:48

    As I said:

    If it was me i would make the top border and the image a row. – Alex Thomas 23 mins ago

    Change you top row to:

    <td valign="bottom">
        <b style="border-top-left-radius:5px; background-color:#fff; display:block; border:3px solid #a3a9ac; border-bottom:0; height:100%; margin:0; padding-bottom:20px; border-right:none;">&nbsp;</b>
    </td>
    <td class="text-center" width="64">
        <img class="top-image" src="https://cdn1.iconfinder.com/data/icons/WPZOOM_Social_Networking_Icon_Set/64/gmail.png">    </td>
    <td valign="bottom">
        <b style="border-top-right-radius:5px; background-color:#fff; display:block; border:3px solid #a3a9ac; border-bottom:0; height:100%; margin:0; padding-bottom:20px; border-left:none;">&nbsp;</b>
    </td>
    

    check out the result - http://jsfiddle.net/562ux.

    I've not tested this in a email Client, but as @Kheema Pandey says, you should try to use inline styles.

    0 讨论(0)
  • 2021-01-24 16:56

    Updated answer:

    You can't use negative margin in html email. To mimic this, there are 2 ways to do it, the nested tables way and the more complex rowspan way:

    <!-- The nested way -->
    
    <table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"><!-- coloring the whole table instead of just the cells you want, will stop gaps forming on forwarding from Outlook -->
      <tr>
        <td width="200" height="80"  bgcolor="#007700">
          <table width="100%" height="80" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="40" bgcolor="#FFFFFF">&nbsp;
              </td>
            </tr>
            <tr>
              <td height="40" bgcolor="#CCCCCC">&nbsp;
              </td>
            </tr>
          </table>
        </td>
        <td width="100" height="80" bgcolor="#4444FF">
         <img alt="" src="" width="100" height="80" style="margin: 0; border: 0; padding: 0; display: block;">
        </td>
        <td width="200" height="80" bgcolor="#FFFFFF">
          <table width="100%" height="80" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="40" bgcolor="#FFFFFF">&nbsp;
              </td>
            </tr>
            <tr>
              <td height="40" bgcolor="#CCCCCC">&nbsp;
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td width="500" height="200" colspan="3">&nbsp;
        </td>
     </tr>
    </table>
    
    <br><br>
    
    <!-- The fancy rowspan way -->
    
    <table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"><!-- coloring the whole table instead of just the cells you want, will stop gaps forming on forwarding from Outlook -->
      <tr>
        <td width="200" height="40" bgcolor="#FFFFFF">&nbsp;
        </td>
        <td width="100"  height="80" rowspan="2" bgcolor="#4444FF">
         <img alt="" src="" width="100" height="80" style="margin: 0; border: 0; padding: 0; display: block;">
        </td>
        <td width="200" height="40" bgcolor="#FFFFFF">&nbsp;
        </td>
      </tr>
      <tr>
        <td width="200" height="40">&nbsp;
        </td>
        <td width="200" height="40">&nbsp;
        </td>
      </tr>
      <tr>
        <td width="500" height="200" colspan="3">&nbsp;
        </td>
     </tr>
    </table>
    

    Original answer:

    For basic positioning:

    Horizontally, use align="left|center|right", vertically use valign="top|middle|bottom"

    Here is how to place an image center top of a table:

    <table width="500" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
      <tr>
        <td height="500" align="center" valign="top">
          <img alt="" src="" width="100" height="100" style="margin: 0; border: 0; padding: 0; display: block;">
        </td>
      </tr>
    </table> 
    
    0 讨论(0)
  • 2021-01-24 17:07

    It is a good practice to use inline style while creating newsletter. Also outlook doesn't support margin negative property.

    in your case the image is not appear center so you can use a inline style here 'style="text-align:center;"'.

    <td style="text-align:center;">
    <img class="top-image" src="https://cdn1.iconfinder.com/data/icons/WPZOOM_Social_Networking_Icon_Set/64/gmail.png" />
    </td>
    
    0 讨论(0)
提交回复
热议问题