I am trying to scale a table cell that has a background image for an email I'm developing. However, I'm having trouble making the height dynamic on the mobile version.
The table cell:
Has no content over the background image
Stacks on mobile
Needs to show the image in a 1:1 ratio, with none of the image cut off at the top or the sides
Is full width on mobile
Fiddle
The fiddle will make the issue clear when you resize your browser window - The cell stacks fine and the width is fine, it's the height that's the problem. The height of the cell is too low, cutting off some of the image.
I need the height to firstly be exactly 385px x 256px on desktop (the exact size of the image), then 100% width on mobile, while also having a full image height on mobile.
There are reasons behind this approach which are not worth boring you with here.
The code:
HTML
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center">
<table width="215" height="256" border="0" cellspacing="0" cellpadding="0" style="float:left;" align="left" class="100p" bgcolor="#eeeeee">
<tr>
<td width="215" style="float:left;" align="left" class="displayproperlyplease 100nopad">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="256">
<tr>
<td align="center">
TEXT
</td>
</tr>
</table>
</td>
<td width="20"></td>
</tr>
</table>
<table width="385" border="0" cellspacing="0" cellpadding="0" class="100p" style="float:left;display:inline" align="right">
<tr>
<td width="20" ></td>
<td background="http://msgfocus.com/files/amf_to_infinity/workspace_83/2-years.jpg" style="background-position:left; background-size:cover; float:left;" bgcolor="#0c0807" width="385" class="100nopad" valign="right" align="middle">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="256">
<tr>
<td align="center">
</td>
</tr>
</table>
</td>
<td width="20"></td>
</tr>
</table>
</td>
</tr>
</table>
CSS
#media (max-width:630px) {
*[class="100p"] {width:100% !important; height:auto !important; text-align:center !important;}
*[class="100pad"] {width:95% !important;}
*[class="100nopad"] {width:100% !important; padding-right: 0 !important; padding-left: 0 !important; float: none !important; text-align: center;}
*[class="displayproperlyplease 100nopad"] {width:100% !important; padding-right: 0 !important; padding-left: 0 !important; float: none !important; text-align: center;}
table[class="wrapper"] {width: 100%;}
table[class="wrapper"] .fl {width: 100% !important;float: left;height: auto;}
}
How can I make the background image on mobile be 100% width, but have the height increase/reduce to ensure none of the image is cut off?
Related
Racking my brain regarding gaps in html email in dark mode. Specifically when three images are sitting next to each other in a table.
<table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td width="230" align="right"><img src="https://s7d5.scene7.com/is/image/overlandsheepskin/ThanksgivingSale11-20-20_02?scl=1" alt="Overland" style="display: block !important; padding: 0 !important; margin: 0 !important;" width="230" height="355" border="0" /></td>
<td width="189"><img src="https://s7d5.scene7.com/is/image/overlandsheepskin/ThanksgivingSale11-20-20_03?scl=1" alt="Overland" style="display: block !important; padding: 0 !important; margin: 0 !important;" width="189" height="355" border="0" /></td>
<td width="231" align="left"><img src="https://s7d5.scene7.com/is/image/overlandsheepskin/ThanksgivingSale11-20-20_04?scl=1" alt="Overland" style="display: block !important; padding: 0 !important; margin: 0 !important;" width="231" height="355" border="0" /></td>
</tr>
</tbody>
</table>
Renders a gap on the right hand column
When you force the scale down to 640px, scaling all images proportionately, it removes the gap. Any idea why this would be?
<table width="640" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr style="background-color:#FFFFFF">
<td width="226" align="right" bgcolor="#FFFFFF"><img src="https://s7d5.scene7.com/is/image/overlandsheepskin/ThanksgivingSale11-20-20_02?scl=1" alt="Overland" style="display: block !important; padding: 0 !important; margin: 0 !important;" width="226" height="355" border="0" /></td>
<td width="186" bgcolor="#FFFFFF" ><img src="https://s7d5.scene7.com/is/image/overlandsheepskin/ThanksgivingSale11-20-20_03?scl=1" alt="Overland" style="display: block !important; padding: 0 !important; margin: 0 !important;" width="186" height="355" border="0" /></td>
<td width="228" align="left" bgcolor="#FFFFFF" ><img src="https://s7d5.scene7.com/is/image/overlandsheepskin/ThanksgivingSale11-20-20_04?scl=1" alt="Overland"style="display: block !important; padding: 0 !important; margin: 0 !important;" width="228" height="355" border="0" /></td>
</tr>
</tbody>
</table>
This has nothing to do with dark mode but it is a long lasting rounding bug in WebKit (Safari’s rendering engine used throught all of iOS) and Blink (Chrome’s rendering engine also used in Android). You should be able to reproduce this on desktop by zooming in or out of your email in either Chrome or Safari. Dark Mode makes this more visible because you get a dark line instead of a white one.
As for why it happens with your table at 650px but not 640px, let's do a bit of maths. Based on your screenshot, your screen size is 1080px wide. Minus the 48px gutter on each side imposed by your email client, that makes a viewport of 984px for your email. At 640px, your email only needs to be scaled up by 1.5375 times. At 650px, your email needs to be scaled up 1.513846153846154… times, which isn't a round count and will inevitably create white lines.
The solution isn't to change your email's width, though, as this problem will inevitably rise at other screen sizes. My advice would be to make sure to use relative units (like %), and code your layout so that all your columns are the same widths. (So for a three columns layout, each "cell" would be 33.333333%).
I have 3 things 1)phone number, 2)social icons and 3)email. First I want all three to be positioned centre in their respective widths.
Then while coming down to mobile screen size say below 480px all of them has to be left aligned and positioned below one after the other 1,2,3 (just like in responsive design).
I'm doing this for a responsive HTML email template. Help me with this!!
<tr>
<td class="cols-wrapper" style="padding-left:12px;padding-right:12px"><br>
<!--[if mso]>
<table border="0" width="576" cellpadding="0" cellspacing="0" style="width: 576px;">
<tr><td width="192" style="width: 192px;" valign="top"><![endif]-->
<table width="192" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row" style="width: 192px;">
<tr>
<td class="col" valign="top" style="padding-left:12px;padding-right:12px;">
<p>Phone: <a style="color:#00a5e7; border-bottom:none;" href="tel:+044 4000 2323">044 1234 5678</a></p>
</td>
</tr>
</table>
<!--[if mso]></td><td width="192" style="width: 192px;" valign="top"><![endif]-->
<table width="192" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row" style="width: 192px;">
<tr>
<td class="col" valign="top" style="padding-left:12px;padding-right:12px;padding-top:10px;">
<img style="float:left;" src="https://cdn0.iconfinder.com/data/icons/social-network-7/50/3-20.png">
<img style="padding:0px 8px; float:left;" src="https://cdn1.iconfinder.com/data/icons/logotypes/32/square-twitter-20.png">
<img src="https://cdn3.iconfinder.com/data/icons/social-media-chamfered-corner/154/google_plus-20.png">
</td>
</tr>
</table>
<!--[if mso]></td><td width="192" style="width: 192px;" valign="top"><![endif]-->
<table width="192" border="0" cellpadding="0" cellspacing="0" align="left" class="force-row" style="width: 192px;">
<tr>
<td class="col" valign="top" style="padding-left:12px;padding-right:12px;">
<p><a style="color:#00a5e7; border-bottom:none;" href="" target="_top">hi#website.com</a></p>
</td>
</tr>
</table>
<!--[if mso]></td></tr></table><![endif]-->
</td>
</tr>
There are multiple points I would like to mention.
First remove this table structure in your code -- which is useless, out of fashion, and increases unnecessary complexity.
Use bootstrap and add col-md-4 in the 3 divs and put your 3 centered objects within it with div { text-align: center } and col-xs-12 in all 3 of them with div { text-align: left }, like:
<div class="col-md-4 col-xs-12>item 1 </div>
<div class="col-md-4 col-xs-12>item 2 </div>
<div class="col-md-4 col-xs-12>item 3 </div>
Even if you don't want to use a framework like bootstrap, write the same code as I told in a media query, like:
#media only screen and (max-width:1024px){
div{
display:inline-block;
width:33%;
text-align:center;
}
}
#media only screen and (max-width: 480px){
div {
display:block;
text-align:left;
}
}
try using a div for .cols-wrapper and remove the inline "float-styles" - add this CSS and you're ready to go. =)
<style media="screen">
.cols-wrapper table{
width: 33.33% !important;
text-align: center;
}
#media (max-width: 480px) {
.cols-wrapper table{
width: 100% !important;
text-align: left;
}
}
</style>
I put an image of height 900px inside a table also of height 900px. But for some reason an added 5px height automatically gets added to the bottom of the table. Here is the code. Could someone explain why this is happening? Thanks.
<body style="margin: 0; padding: 0;">
<table align="center" border="1" cellpadding="0" cellspacing="0" width="650" height="900" style="border-collapse: collapse;" style="border-top: 1px solid white;">
<tr>
<td><img src="dummy.png" alt="#" style="width: 296px; height:auto;"></td>
</tr>
</table>
</body>
An image is an inline element by default. Add the following style to your image and the white space will disappear.
img{display:block}
jsfiddle demo
It's a known problem of tables and td
Set the image as background of the td
http://jsfiddle.net/F6Gds/30/
<body>
<table align="center" border="1" width="296" height="900">
<tr>
<td style="background-image:url(http://dummyimage.com/296x900/ccc/fff);">
</td>
</tr>
</table>
</body>
I'm coding a responsive email, and I'm running onto some troubles with the behavior of some its tables. Please check the attached picture, for the desired effect.
https://dl.dropboxusercontent.com/u/58655025/mail_scenario.jpg
(left: "normal" behavior; right: responsive behavior, when the view width is <= 320px)
I'm not exactly sure of how many elements these blocks (both rectangular and the square ones; number of block elements and contents are dynamic) will have in total, so I want to keep the HTML as dynamic as possible. So, every time a new element is added to each block, it's placed at the right of the previous one and when they cannot fit on that line (due to email's max-width of 620px), I'd like for them to continue below.
And that's the part I'm not able to do. Instead of breaking below, the elements keep growing in the same line, ignoring the email's max-width property.
I'd like for the implementation to be table-based only, in order to guarantee the maximum email-client support as possible.
What can I do to achieve this? Any other suggestion?
Please, check this fiddle for a live example: http://jsfiddle.net/afe33fhv/
Or the HTML code, as required:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Title</title>
<style type="text/css">
/* Client-specific Styles */
#outlook a {padding:0;}
body {width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0; color:#756d85; font-family:Helvetica, Arial, sans-serif;}
body.outlook img { width: auto !important; max-width: none !important;}
.ExternalClass {width:100%;}
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height:100%;}
.backgroundTable {margin:0; padding:0; width:100% !important; line-height:100% !important;}
img {outline:none; text-decoration:none; border:none; -ms-interpolation-mode:bicubic;}
a img {border:none;}
.image_fix {display:block;}
p {margin: 0px 0px !important;}
table td {border-collapse: collapse;}
table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }
a {color: #756d85;text-decoration: none;text-decoration:none!important;}
table[class=full] { width: 100%; clear:both; }
/*IPAD STYLES*/
#media only screen and (max-width: 640px) {
a[href^="tel"], a[href^="sms"] {
text-decoration: none;
color: #000;
pointer-events: none;
cursor: default;
}
table[class=devicewidth] {width:440px !important; text-align:center !important;}
table[class=devicewidthinner] {width:420px !important; text-align:center !important;}
table[class=devicewidthsocial] {width:200px! important; text-align:center !important;}
img[class=banner] {width:440px !important; height:220px !important;}
img[class=colimg2] {width:440px !important; height:220px !important;}
}
/*IPHONE STYLES*/
#media only screen and (max-width: 480px) {
a[href^="tel"], a[href^="sms"] {
text-decoration: none;
color: #000;
pointer-events: none;
cursor: default;
}
table[class=devicewidth] {width:300px !important; text-align:center !important;}
table[class=devicewidthinner] {width:260px !important; text-align:center !important;}
table[class=devicewidthsocial] {width: 200px!important; text-align:center !important;}
img[class=banner] {width: 280px!important; height:140px!important;}
img[class=colimg2] {width: 280px!important; height:140px!important;}
td[class=mobile-hide]{display:none !important;}
}
</style>
</head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
<center>
<!-- | Horizontal blocks | -->
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="backgroundTable">
<tbody>
<tr>
<td>
<table width="620" cellpadding="0" cellspacing="0" border="0" align="center" class="devicewidth" bgcolor="#f2f2f2">
<tbody>
<tr>
<!-- Element 1 -->
<td>
<table width="300" height="100" cellpadding="0" cellspacing="0" border="0" align="center">
<tbody>
<tr>
<td>
<table width="300" height="80" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#7c84ca">
<tbody>
<tr><td width="100%">1</td></tr>
</tbody>
</table>
</td>
</tr>
<tr><td width="100%" height="10" style="font-size:1px; line-height:1px; mso-line-height-rule:exactly;"> </td></tr>
</tbody>
</table>
</td>
<!-- Element 2 -->
<td>
<table width="300" height="100" cellpadding="0" cellspacing="0" border="0" align="center">
<tbody>
<tr>
<td>
<table width="300" height="80" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#bdaabf">
<tbody>
<tr><td width="100%">2</td></tr>
</tbody>
</table>
</td>
</tr>
<tr><td width="100%" height="10" style="font-size:1px; line-height:1px; mso-line-height-rule:exactly;"> </td></tr>
</tbody>
</table>
</td>
<!-- Element 3 -->
<td>
<table width="300" height="100" cellpadding="0" cellspacing="0" border="0" align="center">
<tbody>
<tr>
<td>
<table width="300" height="80" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#d26ec1">
<tbody>
<tr><td width="100%">3</td></tr>
</tbody>
</table>
</td>
</tr>
<tr><td width="100%" height="10" style="font-size:1px; line-height:1px; mso-line-height-rule:exactly;"> </td></tr>
</tbody>
</table>
</td>
<!-- Element 4 -->
<td>
<table width="300" height="100" cellpadding="0" cellspacing="0" border="0" align="center">
<tbody>
<tr>
<td>
<table width="300" height="80" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#d85c79">
<tbody>
<tr><td width="100%">4</td></tr>
</tbody>
</table>
</td>
</tr>
<tr><td width="100%" height="10" style="font-size:1px; line-height:1px; mso-line-height-rule:exactly;"> </td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<!-- | Square blocks | -->
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="backgroundTable">
<tbody>
<tr>
<td>
<table width="620" cellpadding="0" cellspacing="0" border="0" align="center" class="devicewidth" bgcolor="#f2f2f2">
<tbody>
<tr>
<!-- Element 1 -->
<td>
<table width="140" height="140" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#8eb7c2">
<tbody>
<tr><td>1</td></tr>
</tbody>
</table>
</td>
<!-- Element 2 -->
<td>
<table width="140" height="140" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#8ec296">
<tbody>
<tr><td>2</td></tr>
</tbody>
</table>
</td>
<!-- Element 3 -->
<td>
<table width="140" height="140" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#636a34">
<tbody>
<tr><td>3</td></tr>
</tbody>
</table>
</td>
<!-- Element 4 -->
<td>
<table width="140" height="140" cellpadding="0" cellspacing="0" border="0" align="center" bgcolor="#c17b01">
<tbody>
<tr><td>4</td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</center>
</body>
</html>
You probably want to scrap the tables. Set all the blocks to display: inline-block; and they will automatically wrap around to the next line if the parent container hasn't got enough width left.
By using media queries, you can make sure the boxes parent container can only take on certain widths, creating your desired effect.
Here is a jsfiddle demonstrating: http://jsfiddle.net/spkzj05b/2/
Here is a list of css features supported in popular email clients: https://www.campaignmonitor.com/css/
Here is a tool to test the rendering in different email clients: https://litmus.com/email-testing
I have a two column structure. The left holds the left side of one image, and the right holds the right side of the same image. I do this so that a user can click on the left to be directed one place, and the right to be directed another place.
Here's what it looks like:
CSS
<style type="text/css">
body {width: 100%; background-color: #ffffff; margin:0; padding:0; -webkit-font-smoothing: antialiased;font-family: Georgia, Times, serif}
table {border-collapse: collapse;}
table.fixed { table-layout:fixed; }
table.fixed td { overflow: hidden; }
#media only screen and (max-width: 640px) {
body[yahoo] .deviceWidth {width:440px!important; padding:0;}
body[yahoo] .center {text-align: center!important;}
}
#media only screen and (max-width: 479px) {
body[yahoo] .deviceWidth {width:280px!important; padding:0;}
body[yahoo] .center {text-align: center!important;}
}
</style>
HTML
<table width="580" border="0" cellpadding="0" cellspacing="0" align="center" class="deviceWidth" bgcolor="#ffffff">
<tr>
<td class="center" style="padding:0px 0 0 0px">
<table width="50%" border="0" cellpadding="0" cellspacing="0" align="left" class="deviceWidth">
<tr>
<td style="padding: 0px 0px 12px 0px" align="center">
<p style="mso-table-lspace:0;mso-table-rspace:0; margin:0"><img width="290" src="blah" alt="" border="0" style="width: 290px" class="deviceWidth" /></td>
</td>
</tr>
</table>
<table width="50%" border="0" cellpadding="0" cellspacing="0" align="right" class="deviceWidth">
<tr>
<td style="padding: 0px 0px 12px 0px" align="center">
<p style="mso-table-lspace:0;mso-table-rspace:0; margin:0"><img width="290" src="blah2" alt="" border="0" style="width: 290px" class="deviceWidth" />
</td>
</tr>
</table>
</td>
</tr>
</table>
The issue is...I want to make it responsive. But instead of stacking one table on top of the other, I want them to shrink side-by-side so that the image is preserved. How can I achieve this?
EDIT:
Here's a fiddle:
http://jsfiddle.net/54c5W/
I'd like the images to remain side-by-side when I shrink the screen, not stack on top of each other.