Email layout. Changing tr order in responsive table - html

I'm creating a layout for a newsletter. Usually this has to be pretty static but I'm using the Mailchimp guideline to achieve some responsiveness. It works well but the problem is that I would like the second image to come before the text (the problem is very obvious in the example link, it's hard to explain). Basically I would like to achieve something like you could do with Bootstrap using push and pull for example where an image that is placed second becomes first when resizing.
So image and then text when the layout is a single column.
Example: https://codepen.io/SergiOca/pen/vmqMoZ?editors=1010
#media only screen and (max-width: 480px){
#templateColumns{
width:100% !important;
}
.templateColumnContainer{
display:block !important;
width:100% !important;
}
.columnImage{
height:auto !important;
max-width:480px !important;
width:100% !important;
}
.leftColumnContent{
font-size:16px !important;
line-height:125% !important;
}
.rightColumnContent{
font-size:16px !important;
line-height:125% !important;
}
}
<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
<tr>
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="leftColumnContent">
<img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />
</td>
</tr>
</table>
</td>
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="rightColumnContent">
<p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Selección de profesionales en plantilla o freelance.</p>
<p style="font-size: 13px; line-height: 19px; width: 218px;"> A partir de un Job description acordado con el cliente, procedemos a entrevistar y a validar técnicamente a los candidatos que cumplan con los requisitos técnicos y personales, previamente establecidos.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
<tr>
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="leftColumnContent">
<p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Selección de profesionales en plantilla o freelance.</p>
<p style="font-size: 13px; line-height: 19px; width: 218px;"> A partir de un Job description acordado con el cliente, procedemos a entrevistar y a validar técnicamente a los candidatos que cumplan con los requisitos técnicos y personales, previamente establecidos.</p>
</td>
</tr>
</table>
</td>
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="rightColumnContent">
<img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />
</td>
</tr>
</table>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
<tr>
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="leftColumnContent">
<img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />
</td>
</tr>
</table>
</td>
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="rightColumnContent">
<p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Selección de profesionales en plantilla o freelance.</p>
<p style="font-size: 13px; line-height: 19px; width: 218px;"> A partir de un Job description acordado con el cliente, procedemos a entrevistar y a validar técnicamente a los candidatos que cumplan con los requisitos técnicos y personales, previamente establecidos.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>

What you need my son is direction in life.
You can apply the css property direction to swap the order of the table cells. Direction can be applied to text or inline-block elements.
You can apply it different ways.
<row dir="rtl">
<td dir="rtl">
.main-content {direction: rtl; /* Right to Left */}
This is a sample of code how the row or td could be applied:
<!-- header -->
<container class="header">
<row dir="rtl">
<columns large="6" small="12" class="text-right" dir="rtl">
<p class="text-right" style="color: #432a6f; font-size: 12px; text-decoration: underline;">View this email on the web</p>
</columns>
<columns large="6" small="12" dir="rtl">
<img style="display: inline-block" border="0" alt="Image name" src="http://example.com/sample.png" width="184" height="45">
</columns>
</row>
</container>
<!-- .header -->
You can try rtl ot ltr inherit from parent elements.
I would suggest placing direction on a class for the tables in a #media query so that you can swap them in mobile view. Something like this:
#media only screen and (max-width: 600px) {
.leftColumnContent {direction: rtl}
}
For more information on direction, check out:
https://css-tricks.com/almanac/properties/d/direction/
Good luck.

If you have the liberty of using nth-child then you can use
.templateColumns:nth-child(2n) > tbody > tr > td:nth-child(1){
float: right;
}
.templateColumns:nth-child(2n) > tbody > tr > td:nth-child(2){
float: left;
}
but you have to change the markup too, for push and pull to work you need to have the same type of content inside left column and right column.
I have added class .templateColumns to the table
https://codepen.io/srajagop/pen/NjZVpo?editors=1100
Note: nth-child is not supported by all the email readers, gmail doesnt support it

This is what you are after. I have taken one table of yours and given an example of how column swapping can be done. You will need to keep both the elements together for it to work.
The method used here is called hybrid. Both columns are created using div's which is encased in a td
<td valign="top" bgcolor="#FFFFFF" class="templateColumnContainer" style="padding:0px;text-align: center; vertical-align: top; font-size: 0px; direction:rtl;">
This td has direction which will tells everytrhing inside the div to be right to left (direction:rtl)
Next each columns are created using div's which are 50% width of the container td.
<div style="width:100%;max-width:280px;display: inline-block; vertical-align: top; direction:ltr;">
</div>
These div's have a max width of 280px, width of 100% and direction set to left to right (direction:ltr)
Everything inside the div can be coded as 100% width table.
I have added what people call ghost columns. This is Outlook conditional statement that tells outlook that this is a column.
#media only screen and (max-width: 480px){
#templateColumns{
width:100% !important;
}
.templateColumnContainer{
display:block !important;
width:100% !important;
}
.columnImage{
height:auto !important;
max-width:480px !important;
width:100% !important;
}
.leftColumnContent{
font-size:16px !important;
line-height:125% !important;
}
.rightColumnContent{
font-size:16px !important;
line-height:125% !important;
}
.hundred{width:100% !important;}
}
<table border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
<tr>
<td valign="top" bgcolor="#FFFFFF" class="templateColumnContainer" style="padding:0px;text-align: center; vertical-align: top; font-size: 0px; direction:rtl;">
<div style="width:100%;max-width:280px;display: inline-block; vertical-align: top; direction:ltr;">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="rightColumnContent">
<p style ="font-size:21px; color:#009DE0; line-height: 22px;"> Selección de profesionales en plantilla o freelance.</p>
<p style="font-size: 13px; line-height: 19px;"> A partir de un Job description acordado con el cliente, procedemos a entrevistar y a validar técnicamente a los candidatos que cumplan con los requisitos técnicos y personales, previamente establecidos.</p>
</td>
</tr>
</table>
</div>
<!--[if (gte mso 9)|(IE)]>
</td><td width="50%" align="left" valign="top">
<![endif]-->
<div style="width:100%;max-width:280px; display: inline-block; vertical-align: top; direction:ltr;">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="leftColumnContent">
<img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
For the second row of code you can swap the divs around to get the desired result.
Let me know if any of this didnt make sense or you want me to explain further.
Cheers

You can use the HTML dir attribute to manipulate the layout despite what the source order of each column is.
If you layout the email how you want it to appear on mobile, you can then then change the desktop layout using the dir attribute. Using your code, here's an example of a two-column layout where the image will stack above the text on mobile, but appear in the right column on desktop:
<!-- dir=rtl is where the magic happens (rtl = right to left). This swaps the alignment on wide while maintaining stack order on narrow. -->
<table dir="rtl" border="0" cellpadding="0" cellspacing="0" width="600" id="templateColumns">
<tr>
<!-- put this column first in the source order so the image stacks on top of the text on mobile -->
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="rightColumnContent" dir="ltr">
<img src="http://placekitten.com/g/480/300" width="280" style="max-width:280px;" class="columnImage" />
</td>
</tr>
</table>
</td>
<!-- put this column first in the source order so the image stacks on top of the text on mobile -->
<td align="center" valign="top" width="50%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td class="leftColumnContent" dir="ltr">
<p style ="font-size:21px; color:#009DE0; width: 125px; line-height: 22px;";> Selección de profesionales en plantilla o freelance.</p>
<p style="font-size: 13px; line-height: 19px; width: 218px;"> A partir de un Job description acordado con el cliente, procedemos a entrevistar y a validar técnicamente a los candidatos que cumplan con los requisitos técnicos y personales, previamente establecidos.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
Using your existing media query to stack the columns should work wth this code.

Related

HTML Table not full width td

For some reason I can not get the td with 100% inside the table and align the text as center.
How can I make the <td class="order-details"> full width, so it full the 600px of the table obove?
JSFIDDLE: https://jsfiddle.net/61s1cdyo/1/
CODE:
<table class="table-bestelling-content" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#ffffff">
<tr class="details">
<td align="center">
<table class="table-bestelling-content" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#ffffff; max-width: 600px; display: block;">
<tr align="center" class="header">
<td class="order-details">
<h1 style="text-align: left; display: table-cell; padding: 10px 0px;">ORDER DETAILS</h1>
</td>
</tr>
</table>
</td>
</tr>
</table>
Assuming you want to keep the max-width: 600px, you need to remove the display: block from the inner table to make it act like a table.
<table class="table-bestelling-content" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#ffffff">
<tr class="details">
<td align="center">
<table class="table-bestelling-content" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#ffffff; max-width: 600px;">
<tr align="center" class="header">
<td class="order-details">
<h1 style="text-align: left; display: table-cell; padding: 10px 0px;">ORDER DETAILS</h1>
</td>
</tr>
</table>
</td>
</tr>
</table>
Here's a Fiddle
There is a max-width: 600px inline setting for the nested table. If you erase that, it's 100% wide:
https://jsfiddle.net/b594a5d5/1/

Email template td not stacking for mobile?

I am trying to stack two table cells under each other when the email template is viewed on mobile. Although the code works when viewing the email in the browser, it doesn't within mobile email clients?
How can I make the table stack for mobile layout?
Media Query:
#media only screen and (max-width: 600px) {
*[class=hero-block] {
width: 100%;
display: block !important;
text-align: center;
clear: both;
}
}
HTML:
<table bgcolor="000000" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="hero-block">
<img src="hero.jpg" height="265" width="245" />
</td>
<td class="hero-block" width="295">
<table bgcolor="000000" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left">
<font color="#ffffff" face="Arial,Verdana,sans-serif" size="1" style="font-size: 22px; line-height: 22px;">Thanks for signing up</font>
</td>
</tr>
<tr>
<td>
<img style="display: block; border:0; margin: 0; padding: 0;" src="x.gif" height="20" width="1" alt="x" />
</td>
</tr>
</table>
</td>
</tr>
</table>
TD's have stopped stacking in Android for quiet sometime now. A walkaround is to use TH instead, which works on both Android and iOS. Try out my code below in a test email:
#media only screen and (max-width: 600px) {
*[class=hero-block] th{
width: 100%;
display: block !important;
text-align: center;
clear: both;
}
}
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="hero-block">
<tr>
<th align="left" style="font-weight:normal;" bgcolor="#000000">
<font color="#ffffff" face="Arial,Verdana,sans-serif" size="1" style="font-size: 22px; line-height: 22px;">Thanks for signing up</font>
</th>
<th align="left" style="font-weight:normal;" bgcolor="#ffffff">
<font color="#000000" face="Arial,Verdana,sans-serif" size="1" style="font-size: 22px; line-height: 22px;">Thanks for signing up</font>
</th>
</tr>
</table>
When using this code be sure to use font-weight as normal otherwise your text inside the block will be bold.
Cheers

Float:right on outlook responsive code

I'm coding a "responsive" email.
I have a table with 2 td's. An I want that the second one is on the right of the table.
The problem is that the first one can't have fixed width so the table can be responsive.
I tried the "float: worksright" solution but it doesn't work on outlook. (I have tried others but it was the better solution.)
Do you have any idea?
<table style="max-width:600;" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="131" style="padding:25px 0;"><img src="images/autodesk.jpg" style="display:block; height:auto; max-width:131px; width: 100%;"></td>
<td width="25" style="font-size:1px; padding:25px 0;"> </td>
<td style="padding:25px 0; vertical-align:top;"><table style="max-width:444;" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="font-family:Arial, Helvetica, sans-serif; font-size:13px;">
<strong style="color:#ff9933; font-size:11px; text-transform:uppercase;">Autodesk</strong><br/>
<strong style="color:#020a0d; font-size:20px; line-height:27px;">Coleções de indústrias Autodesk</strong><br/>
<br/>
O Kaspersky Anti-Virus proporciona a primeira linha de defesa do seu PC contra vírus através de tecnologias antimalware premiadas, spyware e muito mais. Obtenha proteção real contra os programas maliciosos.<br/>
<br/>
</td>
</tr>
<tr>
<td><table border="0" cellspacing="0" cellpadding="0" style="max-width:444;">
<tr>
<td>
<div style="background-color:#ff9933; color:#ffffff; font-size:14px; font-family:Arial, Helvetica, sans-serif; text-align:center; text-transform:lowercase; padding:5px;">Saber +</div>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
STOP EVERYTHING! I declare myself publicly a stupid person. It just use align="right" in parent table. --' Sometimes we forget the simplest things.
Thank everybody for your help. :)
set width="100%" to table inside second td
Check out this fiddle

Flip Alternating columns in html email for mobile

I have am trying to figure out how to have 3 columns in a table row but hide the first or the last depending on whether it's mobile or desktop. My original thought was to add another TD to the bottom and hide one via css with media queries but that didn't seem to work very well.
Desktop view with alternating images
Mobile view which needs the picture with the lady with the graduation hat above the What is a beneficiary grey box.
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr align="center" valign="middle">
<td align="center" width="50%" class="column" valign="top" style="text-align:left; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight:normal; font-size:16px; color:#44464a; line-height:1.4; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px;"> <img class="person" src="c29229/c29229_4seasons_photos_2.jpg" alt="photo of people" style="width:300; height:auto; border:0 none; display:block;" /> </td>
<td align="center" valign="middle" width="50%" class="column" style="text-align:center; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight:normal; font-size:16px; color:#ffffff; line-height:1.4; padding-top:0px; padding-right:30px; padding-bottom:0px; padding-left:30px; background-color: #ab811d;">
<h2 style="text-align:center; font-weight: normal !important; font-size: 24px; color:#ffffff; margin-bottom: 20px !important;">
<div class="spacer" style="padding-top: 40px; display:none;"> </div>
Complete your beneficiary designation
</h2>
<p style="margin-bottom:0px;">Vea esta correo electrónico en español</p>
</td>
</tr>
</table>
There is a way to do this without relying on media queries, if you'd like total coverage in all email clients. Using the dir attribute along with max-width, you can specify which <td> appears first on wide.
Start by laying out each table 2-column row in a mobile-first manner: The image in the first <td> and the text in the second. Because of the source order, when these layers stack the image will always be on top on the text. Once the column widths exceed their max-width, they'll stack without needing media queries.
This solves mobile, but how do you make some images appear in the right column on desktop? That's where dir comes in. Adding dir=rtl at the parent <td> causes containing elements to run in reverse. So the last column appears first.
Here is a basic example:
<tr>
<!-- dir=rtl is where the magic happens. This can be changed to dir=ltr to swap the alignment on wide while maintaining stack order on narrow. -->
<td dir="rtl" bgcolor="#ffffff" align="center" height="100%" valign="top" width="100%">
<!--[if mso]>
<table role="presentation" border="0" cellspacing="0" cellpadding="0" align="center" width="600">
<tr>
<td align="center" valign="top" width="600">
<![endif]-->
<table role="presentation" border="0" cellpadding="0" cellspacing="0" align="center" width="100%" style="max-width:600px;">
<tr>
<td align="center" valign="top" style="font-size:0; padding: 0;">
<!--[if mso]>
<table role="presentation" border="0" cellspacing="0" cellpadding="0" align="center" width="600">
<tr>
<td align="left" valign="top" width="300">
<![endif]-->
<div style="display:inline-block; margin: 0 -2px; max-width:50%; min-width:280px; vertical-align:top;">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td dir="ltr" style="padding: 0 10px 10px 10px;">
<img src="http://placehold.it/200" width="300" height="" border="0" alt="" style="width: 100%; max-width: 300px; height: auto;">
</td>
</tr>
</table>
</div>
<!--[if mso]>
</td>
<td align="left" valign="top" width="300">
<![endif]-->
<div style="display:inline-block; margin: 0 -2px; max-width:50%; min-width:280px; vertical-align:top;">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td dir="ltr"> <!-- Don't forget to switch dir to ltr here, or else text runs in reverse -->
Text Goes Here
</td>
</tr>
</table>
</div>
<!--[if mso]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
</table>
<!--[if mso]>
</td>
</tr>
</table>
<![endif]-->
</td>
</tr>
If you layout each <tr> in a manner like this which the image in the first column, swapping the order of the columns in each row can be achieved by adding a dir=rtl to the parent <td>.
E-Mail-Clients are a bit tricky with their CSS.
You can order them the way you want them to be on mobile, and then add the following using for desktop:
position: relative;
left: -50%;
The remaining code depends on how you switch between two-column and one-column layout.
Most modern Mail programs support flexbox. With flexbox, you can re-order elements using the order property or by setting the direction to row-reverse.

Align email center in Outlook.com

I want to center my email in Outlook.com.
It works fine in every mail application, but not on Outlook.com
How can I fix this?
Code:
<table class="table-bestelling-content" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#ffffff">
<tr class="header" style="max-width: 600px; display: block; margin-left: auto; margin-right: auto;">
<td>
<table cellpadding="0" cellspacing="0" border="0" width="100%;" >
<tr>
<td align="center" class="email-heading head">
<h1>ORDERBEVESTIGING</h1>
<p>Hi {{htmlescape var=$order.getCustomerFirstname()}},</p>
<p>Bedankt voor je bestelling!</p>
<p>Je bestelling heeft ordernummer {{var order.increment_id}}.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
First off, do not style rows, you're asking for trouble.
I would stay away from margin:auto and just use align's on cells.
You have width="100%;" which will break because of the semicolon.
Change the second tables width to 600 (or whatever you need it to be) and then add align="center" to the cell housing that.
Adding the align to the first cell makes all 600 wide tables inside of that inherit this alignment and will make your entire email centered.
Use this:
<table class="table-bestelling-content" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#ffffff">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" border="0" width="600" >
<tr>
<td align="center" class="email-heading head">
<h1>ORDERBEVESTIGING</h1>
<p>Hi {{htmlescape var=$order.getCustomerFirstname()}},</p>
<p>Bedankt voor je bestelling!</p>
<p>Je bestelling heeft ordernummer {{var order.increment_id}}.</p>
</td>
</tr>
</table>
</td>
</tr>
Try this:
I want to center my email in Outlook.com. It works fine in every mail application, but not on Outlook.com
How can I fix this?
Code:
<table class="table-bestelling-content" cellpadding="0" cellspacing="0" border="0" width="100%" style="background-color:#ffffff">
<tr class="header" style="display: block; margin-left: auto; margin-right: auto;">
<td>
<table cellpadding="0" cellspacing="0" border="0" width="600" >
<tr>
<td align="center" class="email-heading head">
<h1>ORDERBEVESTIGING</h1>
<p>Hi {{htmlescape var=$order.getCustomerFirstname()}},</p>
<p>Bedankt voor je bestelling!</p>
<p>Je bestelling heeft ordernummer {{var order.increment_id}}.</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
Try this:
<table width="100%">
<tr>
<td></td>
<td width="600">
Put all your emails tables/content here
</td>
<td></td>
</tr>
</table>