How to retain image dimensions in Mailchimp templates

此生再无相见时 提交于 2019-11-29 14:55:23

问题


I'm creating a template in Mailchimp to send out newsletters. The template contains a repeatable section with an image of a prefixed size. For some reason it strips the width="" and height="" values from the img element and only includes them if you manually set these within the image settings for each image. This means if a user uploads an image of a different size and doesn't manually enter the correct dimensions then in Outlook the image displays as full size.

To make it even less user friendly on the design editor it uses the width/height css styles to show what the image size is, so it says (for example) 350px wide by 234px tall and you can upload a much larger image and it shows it at 350px width (which would make a user think it was correct). However it does not include the html img width/height values unless you manually specify them which means the image size is wrong in Outlook.

Does anyone know of anyway to force at least the html width variable to be automatically included in the img element? Otherwise users have to manually set the same width/height for each image manually and if they forget then it will not display correctly in Outlook?

Thanks,

Dave


回答1:


For others reference I have now spoken to mailchimp and using a combination of the code at https://www.snip2code.com/Snippet/25348/HTML-Email-Template--max-width-hack-for- (below) and max-width/max-height css values for the img fixes the problem in outlook:

<!--[if (gte mso 9)|(IE)]>
<center>
  <table>
    <tr>
      <td width="600">
        <![endif]-->
        <div style="max-width: 600px; margin: 0 auto;">
          <p>This text will be centered and constrained to 600 pixels even on Outlook which does not support max-width CSS</p>
        </div>
        <!--[if mso]>
      </td>
    </tr>
  </table>
</center>
<![endif]-->



回答2:


To get around this issue you must have a max-width specified on the actual image itself, and make sure it's inlined onto the tag like this:

<img mc:edit="image" src="image.jpg" width="200" style="max-width:200px;">

It doesn't count if it's included in the CSS in the head.

With the markup above the MailChimp editor adds the width="200" AFTER the user edits the image. But if the user doesn't edit the image, sadly no width is added so the fixes above would be worth a try.



来源:https://stackoverflow.com/questions/31182584/how-to-retain-image-dimensions-in-mailchimp-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!