HTML emails in 2013: How to control spacing between elements like paragraphs and images?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 12:58:11

Use inline CSS styles whenever possible (not <style> tags on the page, but style="" attributes). Use HTML attributes (bgcolor, width, height, etc) whenever possible in lieu of CSS styles as there is broader and more consistent support. Define the styles individually on each element - don't rely on inheritance or the cascade.

By this I mean manually set the width, height, padding, margins etc via attribute or inline style on every single td and tr, etc.

You will unfortunately never achieve anything remotely resembling total consistency - usually I aim for it to look good in Gmail, Mac Mail and Outlook and that's the best you can really do. HTML emails are still a decade behind in terms of CSS support, and the extreme variation among the HTML rendering engines used by different mail clients means developing modern sites backwards compatible to IE6 is literally less of a headache than writing a good, heavily-designed email template.

I always refer people to Campaign Monitor's fantastic email client CSS compatibility chart when asked this question. They also have a great guide to coding HTML emails.

You're running into spacing issues mostly because you are using paragraph tags. You need to zero out the margins on your <p> tags. Refer to this article by Email on Acid

Personally, I never use <p> tags as they are less consistent than double <br>-ing it.

Padding works on tables reasonably consistently - It can collapse if someone forwards your email though. Same goes with empty table cells if you don't put a &nbsp; in them. I suggest always using empty cells with nbsp's unless it is something that is not structurally important.

Also, another note about declaring your padding, you'll need to write top/bottom/left/right separately and can't stack them into the one css padding:; declaration unfortunately.

Also your color declarations need to be 6-digit hex, and inline everything before you send.

You need to use super specific inline CSS for emails as all the mail clients like to do their own thing when it comes to rendering the email. It can be more of a pain than, dare I say it, developing for IE! By super specific I mean, don't assume anything! Set everything explicitly.

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