How can I center an image in a html mail that it works in outlook as well.
I tried this:
<th align="center">
<center data-parsed="" class="logo">
<img src="[%embedded-image(1335);logo.png]" alt="" width="207" height="55" border="0"/>
</center>
</th>
as well tried like this
<p style="text-align: center"><img src="[%embedded-image(1335);logo.png]" alt="" width="207" height="55" border="0"/></>
In browser it looks nice. But in outlook not.
What could be a working solution?
thanks.
<center> has been deprecated in favour of text-align: center.
Deprecated This feature has been removed from the Web standards. Though some browsers may still support it, it is in the
process of being dropped. Avoid using it and update existing code if
possible; see the compatibility table at the bottom of this page to
guide your decision. Be aware that this feature may cease to work at
any time.
Ref: <center> - HTML | MDN
Consider using:
text-align: center instead on the containing element (th) of the
img element, or
display: block; margin: auto on the nested img element
...as demonstrated in the embedded code snippet below.
Code Snippet Demonstration:
*:not(code) {
font-family: arial;
}
code {
background: #cccccc;
padding: 3px;
}
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<table style="border: 1px solid gray; width: 600px; border-collapse: collapse;">
<tr>
<th align="center" style="border: 1px solid gray; background: whitesmoke; padding: 10px;">
Using <code>align="center"</code> attribute <sup><small><i class="fa fa-thumbs-o-down"></i> (deprecated)</small></sup> on containing element
</th>
</tr>
<tr>
<th align="center" style="border: 1px solid gray; padding: 10px;">
<img src="https://placehold.it/207x55" alt="" width="207" height="55" border="0"/>
</th>
</tr>
</table>
<br>
<table style="border: 1px solid gray; width: 600px; border-collapse: collapse;">
<tr>
<th align="center" style="border: 1px solid gray; background: whitesmoke; padding: 10px;">
Using <code>text-align:center</code> inline-style property on containing element
</th>
</tr>
<tr>
<th style="border: 1px solid gray; padding: 10px; text-align: center;">
<img src="https://placehold.it/207x55" alt="" width="207" height="55" border="0" style="display: inline-block;"/>
</th>
</tr>
<tr>
<td style="padding: 10px;">
<p>In most cases declaring <code>text-align: center</code> on the containing parent element is enough since <code>img</code> elements are inheritly <em>inline</em>. But to ensure that this behaviour is consistent across all email clients declare <code>display: inline-block</code> on the nested <code>img</code> as well.</p>
</td>
</tr>
</table>
<br>
<table style="border: 1px solid gray; width: 600px; border-collapse: collapse;">
<tr>
<th align="center" style="border: 1px solid gray; background: whitesmoke; padding: 10px;">
Using <code>display: block; margin: auto;</code> inline-style properties on nested <code>img</code>
</th>
</tr>
<tr>
<th style="border: 1px solid gray; padding: 10px;">
<img src="https://placehold.it/207x55" alt="" width="207" height="55" border="0" style="margin: auto; display: block;"/>
</th>
</tr>
</table>
Summary:
To center align an inline element horizontally, you need to:
declare text-align: center on the containing (parent) element
To center align a block element horizontally, you need to:
declare margin: auto on the block element
ensure that it is defined as a block element (display: block)
ensure a specified width is defined (width: 207px)
Vertical & Horizontal Alignment Demonstrations:
For Reference Sake.
Horizontal Alignment (Arbitrary Elements)
Horizontal Alignment (Text Elements)
Vertical Alignment (Arbitrary Elements)
Vertical Alignment (Text Elements)
<table align="center" width="75%">
<tr>
<th>
<div style="margin: 0 auto; text-align: center;">
<img align="center" src="[%embedded-image(1335);logo.png]" alt="" width="207" height="55" border="0"/>
</div>
</th>
</tr>
</table>
Trick is to make the parent table fixed width with align center property.
Giving margin: 0 auto; is 2nd option.
And if it is regular text content, then only align="center" will do the job. Like the following,
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
Your Content
</td>
</tr>
</table>
Hope this one helps.
Related
It should support for html email, so I can't use justify-content and align-items.
I try to use position: absolute for <img />, but It's not working on html email ?
Hot do I make the Twitter icon on the left side and on the same line with 1 2 3 for html email ?
<div
class="footer-container"
style="
position: relative;
background: pink;
position: fixed;
bottom: 0;
width: 100%;"
>
<!-- position is not working on html email -->
<div
class="image-container"
style="position: absolute; top: 30px; left: 24px"
>
<img
src="https://www.citypng.com/public/uploads/preview/-516139511470ymv2hndq6.png"
alt="test"
width="94"
/>
</div>
<div
class="centered"
style="padding-top: 40px; padding-bottom: 40px; padding-right: 30px; text-align:right;"
>
<a>1</a>
<a>2</a>
<a>3</a>
</div>
</div>
In email-templates you have limited support and as such sue techniques that are outdated or would not be semantically correct for normal HTML files.
In this case, you should use a table for layout purposes. You can shrink the table cells to their minimum content by using: style="width: 0; white-space: nowrap;"
<table width="100%">
<tr>
<td>
<img src="https://www.citypng.com/public/uploads/preview/-516139511470ymv2hndq6.png" alt="test" width="94">
</td>
<td style="width: 0; white-space: nowrap;">
<a>1</a>
</td>
<td style="width: 0; white-space: nowrap;">
<a>2</a>
</td>
<td style="width: 0; white-space: nowrap;">
<a>3</a>
</td>
</tr>
</table>
People forget that HTML email Table can be treated as a "grid" layout by using colspan (and rowspan as well). Usually a grid of 6 columns fits best for most of the cases. Knowing you have such a grid, the top row can be constructed as such colspans, and by using text-align:
<style>
td {
border: 1px solid #ddd;
padding: 1rem;
}
</style>
<table cellspacing="0" cellpadding="0" border="0" style="width: 100%; table-layout: fixed; border-collapse: collapse; border: 0px;border-spacing: 0;">
<tbody>
<tr>
<td colspan="2">
<img src="https://i.stack.imgur.com/q9TPY.png" alt="logo" style="display: block; vertical-align: middle; border: 0;" width="57" height="48">
</td>
<td colspan="4" style="text-align: right;">
Link 1
Link 2
Link 3
</td>
</tr>
<tr>
<td colspan="6" style="text-align: center; background: gold;"><br><br>6<br><br><br></td>
</tr>
<tr>
<td colspan="3">3</td>
<td colspan="3">3</td>
</tr>
<tr>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
</tr>
<tr>
<td colspan="5" style="text-align: center; background: #567; color:#fff;">5</td>
<td colspan="1" style="text-align: center; background: #456; color:#fff;">1</td>
</tr>
</tbody>
</table>
I'm currently developing an email that has a 2-column layout in various places. I initially used <div> tags for each column, which worked great in every email client except older versions of Outlook (columns would render at 100% width, regardless of screen size).
To fix the Outlook problem, I simply changed the <div> tags into <td>'s. Now, I have a problem in the iOS mail app (10.1.1) where <td>'s refuse to go full-width on smaller screens. In my code below, you can see that both of the <td class="col-6-article"> elements have a fixed width of 300px, yet when I open the email in the iOS mail app then both of those elements are exactly 50% screen width. Here's a screenshot: http://imgur.com/a/0XsGz
Has anyone else run into this issue with the iOS mail app? I can't figure out why my inline styles and media queries are being ignored, simply because the elements are now table-cells instead of divs.
HTML (sorry, tried my best to clean it up):
<table cellspacing="0" cellpadding="0" width="100%" align="center">
<tbody>
<tr style="vertical-align: top;">
<td width="100%">
<table class="container" style="max-width: 650px; margin: 0 auto;background:#fff;" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr>
<td class="col-6-article" style="display:inline-block; width:300px !important; padding: 0 0 25px 15px;">
<img class="center fullwidth" style="display: block; width: 100%!important; max-width: 325px;" src="http://billykroger.com/img/1mLusPPr.jpg" width="325" />
<h3>Pledges to Ipsum fall short</h3>
<p>Abby Bruell | Jun 2015</p>
<p>Despite good intentions, donors to the London conference have failed to follow through will the pledges they made to aid Syrian refugees. Now, millions of women and children face the consequences of their inaction.</p>
<table>
<tr>
<td style="text-align: center; height: 33px; width: 160px; background: #007c76;">
<table style="margin: 0 auto;">
<tr height="5" style="height:5px"></tr>
<tr style="line-height:normal">
<td><a style="padding: 0; color: #ffffff" href="#">
<span style="color: #FFFFFF; font-size: 14px">READ MORE</span>
</a>
</td>
<td>
<a style="padding: 0; color: #ffffff;" href="#">
<img width="20" height="20" style="height: 20px !important; width: 20px !important;" src="http://cww.convio.net/images/content/pagebuilder/arrow.png" />
</a>
</td>
</tr>
<tr height="5" style="height:5px"></tr>
</table>
</td>
</tr>
</table>
</td>
<td class="col-6-article" style="display:inline-block; width:300px !important; padding: 0 0 25px 15px;">
<img class="center fullwidth" style="display: block; width: 100%!important; max-width: 325px;" src="http://billykroger.com/img/1mLusPPr.jpg" width="325" />
<h3>Pledges to Ipsum fall short</h3>
<p>Abby Bruell | Jun 2015</p>
<p>Despite good intentions, donors to the London conference have failed to follow through will the pledges they made to aid Syrian refugees. Now, millions of women and children face the consequences of their inaction.</p>
<table>
<tr>
<td style="text-align: center; height: 33px; width: 160px; background: #007c76;">
<table style="margin: 0 auto;">
<tr height="5" style="height:5px"></tr>
<tr style="line-height:normal">
<td><a style="padding: 0; color: #ffffff" href="#">
<span style="color: #FFFFFF; font-size: 14px">READ MORE</span>
</a>
</td>
<td>
<a style="padding: 0; color: #ffffff;" href="#">
<img width="20" height="20" style="height: 20px !important; width: 20px !important;" src="http://cww.convio.net/images/content/pagebuilder/arrow.png" />
</a>
</td>
</tr>
<tr height="5" style="height:5px"></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
CSS media query:
#media screen and (max-width: 650px) and (max-device-width: 650px) {
.col-6-article {
width: 100% !important;
display: block !important;
}
}
You have dueling !important tags; you don't need to include !important in the inline css. Change this:
<td class="col-6-article" style="display:inline-block; width:300px !important; padding: 0 0 25px 15px;">
To this:
<td class="col-6-article" style="display:inline-block; width:300px; padding: 0 0 25px 15px;">
Once the !important is removed from the body's inline css, the media query code can override the 300px width and change it to 100% or whatever you want.
Recently I have found a problem on Safari with table.
I have problem with red line (td bottom border or upper).
Here it is on fiddle http://jsfiddle.net/ryrmS/55.
And the full source:
<table border="0">
<tbody>
<tr>
<td style="border-bottom: 2px solid red;">
<div style="width: 20px;"></div>
</td>
<td style="border: 1px solid blue; height: 156px;" rowspan="2">
Content1<br/>
Content2<br/>
Content3<br/>
</td>
</tr>
<tr>
<td style="border-top: 2px solid green;">
<div style="width: 20px;"></div>
</td>
</tr>
</tbody>
</table>
The problem is that the cells do not capture 50% of space in Safari but first takes 0 and third td takes all available height. It works in all browser except Safari.
Also I can't specify fixed height of div or td tag, because it it generated many times in my code and there are different heights and also many tables one inside another.
I can't figure out what the problem is with Safari and how to fix it. Does anyone have some hints?
It looks like:
If you are explicitly setting height: 156px; on the td that spans both rows, why not just set the other 2 tds to height: 88px;?
See working jsFiddle demo
HTML
<table border="0">
<tbody>
<tr>
<td style="border-bottom: 2px solid red; height: 88px;">
<div style="width: 20px;"></div>
</td>
<td style="border: 1px solid blue; height: 156px;" rowspan="2">
Content1<br/>
Content2<br/>
Content3<br/>
</td>
</tr>
<tr>
<td style="border-top: 2px solid green; height: 88px;">
<div style="width: 20px;"></div>
</td>
</tr>
</tbody>
</table>
CSS
table { border-collapse: separate; border-spacing: 0; }
td { vertical-align: middle; text-align: center; }
RESULTS
(tested in FF, Chrome, Safari, and IE)
I'm trying to figure out why my tables cells are not displaying at the height I specify:
<html>
<head>
</head>
<body>
<table style="border: 1px solid black; border-radius: 10px; padding: 0px;padding-top: 6px; margin: 0px;" align="left" bgcolor="#FFFFFF" border="1" cellpadding="0" cellspacing="0" height="842" width="595">
<tbody>
<tr><td height="100">Test</td></tr>
<tr><td height="100">Test</td></tr>
</tbody>
</table>
</body>
</html>
On my browser (Firefox), this page displays with each cell taking 50% of the height of the table (covering the whole table) instead of the specified 100px each cell. I've tried every combination, setting the tr height (which actually doesn't exist), and the td height as I've posted.
I need to avoid using CSS as I'm generating HTML for emails and email clients are not very tolerant to CSS. I would like my table as much as possible to be set using HTML tag attributes.
EDIT
Now I'm really confused. Even setting the height with CSS doesn't work:
<table style="border: 1px solid black; border-radius: 10px; padding: 0px;padding-top: 6px; margin: 0px;" align="left" bgcolor="#FFFFFF" border="1" cellpadding="0" cellspacing="0" height="842" width="595">
<tbody>
<tr><td style="height: 100px;">Test</td></tr>
<tr><td style="height: 100px;">Test</td></tr>
</tbody>
</table>
EDIT
Someone posted a JSFiddle in the comments saying it worked. But here is a screenshot of that fiddle on my browser (Firefox):
I guess the question now is why can I not set the row height on Firefox?
Just figured it out. On Firefox you must set display: block; in the CSS or the table height will not be applied:
<body>
<table style="border: 1px solid black; border-radius: 10px; padding: 0px;padding-top: 6px; margin: 0px; display: block;" align="left" bgcolor="#FFFFFF" border="1" cellpadding="0" cellspacing="0" height="842" width="595">
<tbody>
<tr><td height="100" style="display: block">Test</td></tr>
<tr><td height="100" style="display: block">Test</td></tr>
</tbody>
</table>
</body>
I am working on HTML email and trying to center a green TD in a white TR so that there's a 20px white margin on the left and right of the green box.
I tried setting TD width for the green portion and setting margin 0 auto but the green just expands to the width of the TR.
Tried putting in 2 more TDs to push the green TD into the center and that didn't work either.
Including the code snippet, am having trouble with the TR that has #a6d971.
<table cellspacing="0" cellpadding="0" border="0" width="600" height="" bgcolor="" style="margin: 0 auto;">
<tbody>
<tr>
<td style="margin: 0 auto;">
<img width="600" height="23" padding="0" src="assets/graphic_scalloped_top.png" alt="" style="display: block;" />
</td>
</tr>
<tr bgcolor="#fff" height="75">
<td valign="top" style="text-align:center;">
<p style="margin:0; padding-bottom: 3px; padding-top: 3px; color:#545d69; font-size: 24px; text-align:center; font-family: Arial, Helvetica;">
Regular sales happen every day
</p>
<p style="margin:0; padding-bottom: 3px; padding-top: 3px; color:#4bc1d6; font-size: 16px; text-align:center; font-family: Arial, Helvetica;">
9am - 11pm
</p>
</td>
</tr>
<tr bgcolor="#fff" height="75" padding="10">
<td bgcolor="#000" width="20"></td>
<td bgcolor="#a6d971" width="300" style="margin: 10;">
</td>
<td bgcolor="#000" width="20"></td>
</tr>
<tr bgcolor="#fff">
<td valign="top">
<table cellspacing="0" cellpadding="10" border="0" align="center" width="100%" bgcolor="#fff" style="">
<tbody>
<tr>
<td height="80" style="font-family: Helvetica, Arial, sans-serif; font-size: 18px; font-weight: bold; color: #555; background:url('assets/graphic_9am.png') no-repeat; background-position: 10% center; padding:10px; margin:0;">
<h3>Nine # Nine</h3>
<p>Fuel up! Dresses, tunics and other items including:</p>
</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td style="margin: 0 auto;">
<img width="600" height="23" padding="0" src="assets/graphic_scalloped_bottom.png" alt="" style="display: block;" />
</td>
</tr>
</tbody>
</table>
Switch to DIV's and CSS, most emails client supports styles pretty well, you can use a DIV inside your TD element, it'll be easy to center or do other things you might want.
For Example
<tr style="background-color: white;">
<td style="background-color: green;">
<div style="background-color: purple; margin-right: 20px; margin-left: 20px;">Content Here</div>
</td>
</tr>
Also note if you use DIV's you can also avoid tables.
Hack on top of a hack.
<table width="100%" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="border-left: 20px solid white; border-right: 20px solid white; background: green; color: white; text-align: center;">
This is stuff.
</td>
</tr>
</tbody>
</table>
http://jsfiddle.net/zy6GU/
Incidentally, the same thing should work with a DIV:
<div style="border-left: 20px solid white; border-right: 20px solid white; background: green; color: white; text-align: center;">This is a DIV.</div>
http://jsfiddle.net/zy6GU/1/
If you HAVE to use tables, might as well abuse them a little:
<table><tr align="center">
<td width="50%">one</td>
<td style="background-color:green">two</td>
<td width="50%">three</td>
</tr></table>
http://jsfiddle.net/mblase75/yntfu/
I'm not a CSS expert but this works for me (with no extra tags) :
<table>
<tr style="background-color: white; border: 1px solid black;">
<td style="background-color: green; display: block; margin: 0 20px;">
<!-- Content -->
</td>
</tr>
</table>
What are you talking about 'for emails'? You mean an email address, like Email Me? If so you'd want some css that centers the link in the TD, or in combination with colspan on the TD.