-
-
Save elidickinson/5525752 to your computer and use it in GitHub Desktop.
<!--[if mso]> | |
<center> | |
<table><tr><td width="580"> | |
<![endif]--> | |
<div style="max-width:580px; margin:0 auto;"> | |
<p>This text will be centered and constrained to 580 pixels even on Outlook which does not support max-width CSS</p> | |
</div> | |
<!--[if mso]> | |
</td></tr></table> | |
</center> | |
<![endif]--> |
Hi everybody,
I have used @philipp-klinz 's solution. And I want the template to be max 600px width. But unfortunately, the templte is always 800px max. Can anyone please help me to solve this problem. Here I am giving the full code so that you can find if there is anything else that is causing the problem. Waiting for your reply. Thank you in advance.
<style type="text/css">
* {
box-sizing: border-box;
font-family: roboto, sans-serif;
}
body {
width: 600px;
max-width: 100%;
margin: auto;
padding: 0;
}
/*
@tab Topbar
@section Menu
@style Topbar Menu
*/
.topbar {
/*@tab Topbar
@section Menu
@Style Topbar Menu*/
width: 100%;
/@editable/
background-color: #1f3754;
font-family: Roboto, sans-serif;
/@editable/
font-size: 30px;
/@editable/
color: #ffffff;
}
/*
@tab Topbar
@section Menu Row
@Style Topbar Menu row
*/
.topbar-menu {
/*@editable*/
max-width: 60%;
width: 60%;
display: inline-block;
}
.topbar-menu,
.topbar-social-icons {
padding: 15px 5px;
}
/*
@tab Topbar
@section Social Icons Row
@style Social Icons row
*/
.topbar-social-icons {
/*@editable*/
max-width: 40%;
width: 40%;
display: inline-block;
}
.topbar-menu a {
/*@editable*/
color: #ffffff;
}
/*
@tab Page
@section Social Icons
@style Topbar Social Icons
*/
.topbar-menu a,
.topbar-social-icons a {
/*@editable*/
text-decoration: none;
}
.topbar-social-icons a {
/*@editable*/
margin: 0 10px;
}
.topbar-social-icons a img {
/*@editable*/
max-width: 30px;
}
/*
@tab Header
@section Header Image
@style Header Image
*/
.header-image {
/*@tab Header
@section Header Image
@Style Header Image*/
max-width: 800px;
width: 100%;
}
/*
@tab Body
@section Body
@Style Body
*/
.body {
/*@editable*/
width: 100%;
/*@editable*/
padding: 36px;
}
/*
@tab Intro
@section Intro Text
@style Intro Text
*/
.intro-text {
/*@editable*/
font-size: 20px;
/*@editable*/
color: #1f3754;
/*@editable*/
text-align: center;
/*@editable*/
font-weight: bold;
}
/*
@tab Lines
@section Blue Line
@style Blue Line
*/
.hr-blue {
/*@editable*/
border-bottom: 4px solid #1f3754;
}
.features {
max-width: 100%;
}
/*
@tab Features
@section Single feature
@style Single feature
*/
.single-feature {
/*@editable*/
min-width: 24%;
text-align: center;
display: inline-block;
}
/*
@tab Features
@section Feature Header
@style Feature Header
*/
.single-feature-header {
/*@editable*/
font-family: Roboto, sans-serif;
/*@editable*/
font-size: 30px;
/*@editable*/
color: #1f3754;
/*@editable*/
font-weight: bold;
/*@editable*/
margin-bottom: 0;
/*@editable*/
padding-bottom: 0;
}
.single-feature-icon {
/*@editable*/
max-height: 85px;
/*@editable*/
margin: auto;
}
.feature-arrow {
/*@editable*/
max-width: 30px;
}
/*
@tab Features
@section Description
@style Description
*/
.single-feature-description {
/*@editable*/
font-family: Roboto, sans-serif;
/*@editable*/
font-size: 14px;
/*@editable*/
margin-top: 0;
/*@editable*/
padding-top: 0;
}
.single-feature-description,
.description {
color: #6d6d6d;
}
/*
@tab Body Description
@section Description
@style Description
*/
.space {
/*@tab Body Description
@section Description
@Style Description*/
height: 30px;
display: block;
}
.description {
/*@editable*/
font-family: Roboto, sans-serif;
/*@editable*/
font-size: 16px;
/*@editable*/
text-align: center;
}
.signature-logo {
/*@editable*/
max-width: 50%;
}
/*
@tab Footer
@section Footer
@style Footer
*/
.footer {
/*@editable*/
width: 100%;
/*@editable*/
padding: 10px 0;
/*@editable*/
background-color: #1f3754;
}
.footer-details {
/*@editable*/
width: 60%;
/*@editable*/
margin: auto;
/*@editable*/
text-align: center;
background-color: #1f3754;
}
/*
@tab Footer
@section Footer Icons
@style Footer Icons
*/
.footer-social-icons a {
/*@editable*/
text-decoration: none;
}
.footer-social-icons a img {
/*@editable*/
width: 25px;
margin: 10px;
}
/*
@tab Footer
@section Footer Unsubscribe
@style Footer Unsubscribe
*/
.copyright,
.footer-preferences {
/*@editable*/
font-family: Roboto, sans-serif;
/*@editable*/
font-size: 14px;
/*@editable*/
color: #ffffff;
background-color: #1f3754;
}
.footer-preferences a {
/*@editable*/
color: #ffffff;
/*@editable*/
text-decoration: underline;
}
@media only screen and (max-width: 450px) {
/*
@tab Responsive
@section Mobile
@style Single Feature
*/
.single-feature {
/*@editable*/
max-width: 100% !important;
display: block !important;
}
}
@media only screen and (max-width: 450px) {
.footer-details {
width: 90% !important;
}
}
@media only screen and (min-width: 451px) and (max-width: 576px) {
/*
@tab Responsive
@section Big Screen Smart Mobile Topbar
@style Topbar
*/
.topbar {
/*@editable*/
font-size: 25px !important;
}
}
@media only screen and (min-width: 451px) and (max-width: 576px) {
/*
@tab Responsive
@section Big Screen Smart Mobile Topbar Social Icons
@style Topbar Social Icons
*/
.topbar-social-icons a img {
/*@editable*/
max-width: 20px !important;
}
}
@media only screen and (min-width: 451px) and (max-width: 576px) {
/*
@tab Responsive
@section Big Screen Smart Mobile Intro Text
@style Intro Text
*/
.intro-text {
/*@editable*/
font-size: 18px !important;
}
}
@media only screen and (min-width: 451px) and (max-width: 576px) {
/*
@tab Responsive
@section Big Screen Smart Mobile Single Feature
@style Single Feature
*/
.single-feature {
/*@editable*/
width: 100% !important;
display: block !important;
}
}
@media only screen and (min-width: 451px) and (max-width: 576px) {
/*
@tab Responsive
@section Big Screen Smart Mobile Single Footer Text area
@style Single Footer Text area
*/
.footer-details {
/*@tab Responsive
@section Big Screen Smart Mobile Single Footer Text area
@Style Single Footer Text area*/
width: 70% !important;
}
}
@media all and (min-width: 576px) and (max-width: 750px) {
/*
@tab Responsive
@section Topbar on Tablets
@style Topbar on Tablets
*/
.topbar {
/*@editable*/
font-size: 25px !important;
}
}
@media all and (min-width: 576px) and (max-width: 750px) {
/*
@tab Responsive
@section Topbar Social Media Icons on Tablets
@style Topbar Social Media Icons on Tablets
*/
.topbar-social-icons a img {
/*@editable*/
max-width: 25px !important;
}
}
@media all and (min-width: 576px) and (max-width: 750px) {
/*
@tab Responsive
@section Footer Text Area on Tablet
@style Footer Text Area on Tablet
*/
.footer-details {
/*@editable*/
width: 70% !important;
}
}
</style>
|
Do you use conditional outlook comment code around every table or just inner tables whose width you need to control?
I needed a responsive (fluid) table that had a maximum width of 600px and this code is working for me:
<!--[if mso]>
<table><tr><td width="600">
<![endif]-->
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="max-width: 600px">
<tr>
<td>
<!-- Your content here -->
</td>
</tr>
</table>
<!--[if mso]>
</td></tr></table>
<![endif]-->
Awesome
Thank you !!
I was making an email in Pardot (marketing tool) and the tool automatically changes the width attribute on my images to the width of the image. Pardot does not allow me to set a maximum width.
<!-- Outlook ignores the max-width -->
<img src="https://example.com/images/my-image.jpg" style="max-width: 200px" width="400">
Since outlook does not care if you set a max-width in the style attribute the only solution is to change the width of the image back after it was uploaded to Pardot.
None of the examples above seemed to work for images (in Outlook) so the only solution for me was to recommend uploading images with the same width as the original image or to change the width back after uploading an image.
Dope. Thanks for this.
This saved me hours of the worst kind of debugging time, thank you!!
I'm still having trouble... I tried using this but maybe I'm using it in the wrong place? This is the original before I tried @philipp-klinz idea.
``
/*@editable Vertical Line Color*/
/*@theme line-color*/
}
.sidebarOne td,
.sidebarTwo td,
.sidebarL td,
.sidebarR td {
padding: 0 10px;
}
.sidebarThree td {
padding-left: 10px;
}
.sidebarOne td.spacer,
.sidebarTwo td.spacer,
.sidebarThree td.spacer,
.sidebarL td.spacer,
.sidebarR td.spacer {
font-size: 10px;
padding: 0;
}
/* * @section Background_Colors_Layout * @title Colors and Layout */
.col_L {
/*@editable Left Column Width*/
width: 50%;
/*@editable Left Background Color*/
/*@theme body-background-color*/
background-color: #e3f4fe;
}
/* * @section Background_Colors_Layout * @title Colors and Layout */
.col_R {
/*@editable Right Column Width*/
width: 50%;
/*@editable Right Background Color*/
/*@theme body-background-color*/
background-color: #e3f4fe;
}
/* * @section Background_Colors_Layout * @title Colors and Layout */
.main {
/*@editable Content Background Color*/
/*@theme body-background-color*/
background-color: #e3f4fe;
}
/* * @section Background_Colors_Layout * @title Colors and Layout */
#footer {
/*@editable footer-background-color*/
background-color: #00447A;
}
/* * @section Top_Bar * @title Top Bar */
#view_browser p {
text-align: center;
/*@editable Text Color*/
/*@theme top-text-color*/
color: #3C3C3C;
/*@editable Text Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Text Size*/
font-size: 10px;
}
/* * @section Top_Bar * @title Top Bar */
#view_browser a {
/*@editable Link Color*/
/*@theme top-link-color*/
color: #fff;
}
/* * @section Left_Headline * @title Left Column Headline */
.sidebarL .titleSide {
letter-spacing: 1.5;
text-align: center;
margin: 5px 0 0 0;
font-weight: bold;
/*@editable Headline Color*/
/*@theme headline-text-color*/
color: #1C4675;
/*@editable Headline Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Headline Font Size*/
font-size: 16px;
}
/* * @section Left_Column * @title Left Column */
.sidebarL .textSide {
line-height: 1.4 !important;
/*@editable Text Color*/
/*@theme text-color*/
color: #3C3C3C;
/*@editable Text Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Text Font Size*/
font-size: 12px;
}
/* * @section Left_Column * @title Left Column */
.sidebarL a {
/*@editable Link Color*/
/*@theme link-color*/
color: #3c3c3c;
}
/* * @section Right_Headline * @title Right Column Headline */
.sidebarR .titleSide {
letter-spacing: 1.5;
text-align: center;
margin: 5px 0 0 0;
font-weight: bold;
/*@editable Headline Color*/
/*@theme headline-text-color*/
color: #00447A;
/*@editable Headline Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Headline Font Size*/
font-size: 16px;
}
/* * @section Right_Column * @title Right Column */
.sidebarR .textSide {
line-height: 1.4 !important;
/*@editable Text Color*/
/*@theme text-color*/
color: #3C3C3C;
/*@editable Text Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Text Font Size*/
font-size: 12px;
}
/* * @section Right_Column * @title Right Column */
.sidebarR a {
/*@editable Link Color*/
/*@theme link-color*/
color: #3c3c3c;
}
/* * @section Background_Colors_Layout * @title Colors and Layout */
/* * @section Main_Column_Headline * @title Main Column Headline */
#content .titleContent {
text-align: center;
margin: 0;
font-weight: bold;
/*@editable Headline Color*/
/*@theme headline-text-color*/
color: #00447A;
/*@editable Headline Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Headline Font Size*/
font-size: 30px;
}
/* * @section Main_Column_Sub-Headline * @title Main Column Sub-Headline */
#content .SubtitleContent {
text-align: center;
margin: 0;
font-weight: normal;
/*@editable Sub-Headline Color*/
/*@theme headline-text-color*/
color: #3B92F5;
/*@editable Sub-Headline Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Sub-Headline Font Size*/
font-size: 18px;
}
.titleContent p,
.SubtitleContent p,
.footer p {
margin: 0;
}
.textContent p {
text-align: center;
line-height: 1.4 !important;
margin: 0 0 12px 0;
}
/* * @section Main_Column * @title Main Column */
#content .textContent,
#content ul,
#content ol {
line-height: 1.4 !important;
/*@editable Text Color*/
/*@theme text-color*/
color: #3C3C3C;
/*@editable Text Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Text Font Size*/
font-size: 18px;
}
/* * @section Main_Column * @title Main Column */
#content a {
/*@editable Link Color*/
/*@theme link-color*/
color: #3c3c3c;
}
/* * @section Action_Link * @title Action Link */
.actionLinkContainer {
/*@editable Alignment*/
text-align: center;
margin-top: 5px;
}
/* * @section Action_Link * @title Action Link */
.twoColumn{
padding-top:15px;
}
.twoColumn .actionLinkContainer a,
.threeColumn .actionLinkContainer a,
#content .actionLinkContainer a {
/*@editable Text Color*/
/*@theme text-color*/
color: #00447A;
/*@editable Text Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Text Font Size*/
font-size: 12px;
/*@editable Link Color*/
/*@theme link-color*/
/*@editable Button Color*/
/*@important*/
}
/* * @section Footer */
#footer {
height: 40px;
margin: 0 auto;
padding: 10px;
}
/* * @section Footer */
#footer p{
text-align:center;
}
#footer {
/*@editable Text Color*/
/*@theme footer-text-color*/
color: #fff;
/*@editable Text Font*/
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
/*@editable Text Font Size*/
font-size: 11px;
}
/* * @section Footer */
#footer a {
/*@editable Link Color*/
/*@theme footer-link-color*/
color: #fff;
}
body {
margin: 0;
padding: 0;
background-repeat: no-repeat;
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
font-size: 12px;
width: 100% !important;
/* Hotmail body centered */
display: block !important;
}
div.ec_attachments {
width: 500px;
margin: 20px 0;
background-color: #fff;
font-size: 13px;
text-align: left;
font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;
}
div.ec_attachments li {
border-top: 1px solid #cccccc;
padding: 10px;
}
div.ec_attachments ul {
padding-right: 40px;
}
div.ec_attachments_text {
padding: 10px 0 0 10px;
}
#attachments div.ecaction_edit {
border: 1px solid #cccccc;
}
#page {
margin: 0px auto;
padding: 0;
}
#view_browser {
width: 600px;
}
a img {
border: none;
}
#global_masthead {
width: 600px;
}
#main {
width: 600px;
}
.spacer {
font-size: 10px;
padding: 0;
}
.sidespacer {
font-size: 5px;
padding: 0;
}
.mainTable img {
height: auto !important;
}
</style>
<style data="noinline">
body {
width: 100% !important;
/*Hotmail Fix*/
}
</style>
<style data="mobile" data-title="Mobile" data-width="335" data-rule="@media only screen and (max-width: 480px), screen and (max-device-width: 480px)">
@media only screen and (max-width: 480px),
screen and (max-device-width: 480px) {
body {
-webkit-text-size-adjust: 100%;
line-height: 125%
}
#page .ec_item {
padding-top: 0px;
}
#page .ec_item{
padding-bottom: 10px;
}
#page .ec_img{
padding-top: 0px;
}
.actionLinkContainer{
padding-bottom: 10px;
}
#header_img {
line-height: normal !important;
}
table[class*="mainTable"] img,
td[id="content"] img,
td[id="sidebarL"] img,
td[id="sidebarR"] img {
max-width: 100% !important;
height: auto !important;
}
table[class*="mainTable"] p {
margin: 0.5em 0 !important;
}
table[class="pageTable"],
table[id="global_masthead"],
table[id="main"],
div[class="ec_attachments"] {
width: 320px !important;
}
td[id="content"] {
padding-bottom: 0 !important;
}
td[class*="textContent"],
td[class*="textSide"] {
line-height: 1.4 !important;
font-size: 14px !important;
}
/** * @section Mobile */
td.titleContent {
/*@editable Headline Font Size*/
font-size: 20px !important;
line-height: 1 !important;
height: auto !important;
}
/** * @section Mobile */
td[class*="SubtitleContent"] {
/*@editable Subtitle Font Size*/
font-size: 18px !important;
line-height: 1 !important;
height: auto !important;
/*@editable Subtitle Font Weight*/
font-weight: normal !important;
}
/** * @section Mobile */
td[class*="textContent"] {
line-height: 1.4 !important;
/*@editable Body Font Size*/
font-size: 14px !important;
line-height: 1 !important;
height: auto !important;
}
/** * @section Mobile */
td[class*="textContent"] a {
line-height: 1.4 !important;
/*@editable Link Font Size*/
font-size: 14px !important;
}
/** * @section Mobile */
div[class*="actionLinkContainer"] a {
/*@editable Action Link Size*/
font-size: 14px !important;
/*@editable Action Text Color*/
/*@important*/
color: #00447A !important;
/*@editable Link Underline*/
text-decoration: underline !important;
/*@editable Button Color*/
/*@important*/
background-color: transparent !important;
/*@editable Corner-Radius*/
/*@important*/
border-radius: 2px !important;
padding: 5px !important;
}
table[class*="sidebarOne"],
table[class*="sidebarTwo"],
table[class*="sidebarThree"],
table[class*="sidebarL"],
table[class*="sidebarR"] {
padding: 5px 15px !important;
border: 0 !important;
width: 100% !important;
}
table[class*="sidebarL"] tr:first-child td img,
table[class*="sidebarR"] tr:first-child td img {
padding-bottom: 5px;
}
td[class*="main"] {
padding-bottom: 5px !important;
}
/** * @section Mobile */
td[class*="titleSide"] {
/*@editable Sidebar Header Font Size*/
font-size: 18px !important;
line-height: 1 !important;
height: auto !important;
/*@editable Sidebar Header Font Weight*/
font-weight: bold !important;
}
/** * @section Mobile */
td[class*="textSide"] {
line-height: 1.4 !important;
/*@editable Sidebar Font Size*/
font-size: 14px !important;
line-height: 1.4 !important;
height: auto !important;
}
/** * @section Mobile */
td[class*="textSide"] a {
line-height: 1.4 !important;
/*@editable Sidebar Link Font Size*/
font-size: 14px !important;
}
td[class*="spacer"],
table[id="view_browser"] {
display: none !important;
}
/** * @section Mobile */
table[id="footer"] {
/*@editable Footer Font Size*/
font-size: 9px !important;
}
table[id="footer"] td {
display: block !important;
width: 100% !important;
}
table[id="footer"] td[class*="powered_by"] {
text-align: center !important;
font-size: 14px !important;
}
table[id="footer"] td[class*="powered_by"] img {
width: auto !important;
}
table[id="footer"] a {
text-decoration: none;
}
span[class="callout"]{
font-size:30px!important;
}
span[class="callout_2"]{
font-size:20px!important;
}
.tablet-button, .tablet-button td, .tablet-button a{
height:40px!important;
width:200px!important;
}
}
</style>
<!--[if lt IE 11]> <style data="mobile-ie" data-condition="if lt IE 11" data-rule="@media only screen and (max-width: 480px), screen and (max-device-width: 480px)"> @media only screen and (max-width: 480px), screen and (max-device-width: 480px) { ignore { rule-ignored: "why"; } table[class*="mainTable"] img, img { max-width:320px !important;} #header_img { width: 320px !important } div.ec_attachments, table, tbody, tr, td { width:100% !important;} } </style> <![endif]-->
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" align="center" class="mainTable" width="100%">
<tbody>
<tr>
<td>
<table align="center" class="pageTable" width="600">
<tbody>
<tr>
<td>
<table cellspacing="0" cellpadding="0" border="0" align="center" id="main">
<tbody>
<tr>
<td background="https://torahmates.org/email/2019/img/test-header.jpg" bgcolor="#00447A" valign="top" style="text-align:center; font-family: 'Open Sans', sans-serif; color: #ffffff; line-height: 32px; text-align:center; padding:0 5% 100px; background-size:cover; background-position:center center;">
<table width="83" cellpadding="0" cellspacing="0" border="0" align="center" class="devicewidth">
<tbody>
<tr>
<td valign="middle" width="166" style="padding: 10px 0 50px 0px; text-align:left;" class="logo">
<div class="imgpop">
<a href="http://www.oorah.org/events"><img src="https://torahmates.org/email/2019/img/events-logo-white.png" alt="oorah" width="83" height="65" /></a>
</div>
</td>
</tr>
</tbody>
</table>
<table width="100%" cellspacing="0" cellpadding="0" data-block-group="main_column" class="ec_repeat">
<tbody>
<tr>
<td valign="top" class="ec_item textContent">
<p><span class="callout" style="font-family: 'Open Sans', Arial, Helvetica, sans-serif; color: #ffffff; font-size: 36px; text-align: center; font-weight:bold; letter-spacing: 1px; display: block; line-height: 1.25;">You may be in the stands, but you're one of the players.</span><br><span class="callout_2" style="font-size: 24px; line-height: 1.25; text-align: center; letter-spacing:.3px; font-family:'Open Sans', sans-serif; color:#fff;">Join over 100,000 in celebration of Torah Study at the 13th Siyum Hashas.
</span></p>
</td>
</tr>
</tbody>
</table>
</div>
|
Thank you for THE Solution!
You're the real MVP 🤗
Isn't better use table and td?
love it, thanks @elidickinson
still works after 8 years
Great solutions everyone! Although none of them can stand the normal text mixed with super long words (or just text with no spaces). Windows Mail/Outlook (2007, 2010, 365) keep stretching the table...
NB: break-all and hyphens wouldn't help since the first will break normal words, and the later will brake the links.
@philipp-klinz Great job this works perfectly to center object without center text.
If someone want to center object and text, simply use style="text-align:center;
.
@philipp-klinz fyi I left your solution as an answer to this StackOverflow question: Is there an equivalent of CSS max-width that works in HTML emails?: answer