隐藏来自Gmail的表格"显示以下图像"

时间:2017-09-06 12:52:09

标签: html css gmail media-queries html-email

我正在开发一个HTML电子邮件,它使用两列用于桌面设计,一个用于移动设计。而不是处理使用媒体查询定位桌面版本的特定元素的所有复杂性,并尝试使它们适用于移动设备(这是电子邮件的噩梦......),我想我会创建一个完全独立的表格移动设备并使桌面版本消失(显示:无),断点低于450px。

现在,这有效;但是,在桌面(450px以上)上,我将移动表设置为(显示无;显示:无!重要;),这就出现了问题。在大于450px的屏幕尺寸上打开电子邮件时(在GMAIL中,而不是在浏览器中。我使用名为" freshmail"的服务进行测试),最初只显示桌面表;但是,没有图像存在。 Gmail要求"显示以下图片"然后点击这会重写我的样式表,这样移动表也会出现,即使我也没有明确说明。

我知道这是一项棘手的事情,我已经尝试了许多解决方法来克服它,但没有一种方法可行。如果有人能帮助我实现这一目标,我将非常感激。

我的代码如下:

<!DOCTYPE html>
<html>
    <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>

        <style>

        @media (min-width: 451px) {
            #mobile {
                display: none;
                display: none !important;
            }
        }

        @media (max-width: 450px) {
            #desktop {
                display: none !important;
            }

            #mobile {
                display: block !important;
            }
        }

        </style>

    </head>


    <body style="width: 100% !important; margin: 0; padding: 0; font-size: 13.5px; line-height: 1.4; font-family: Helvetica; overflow-x: hidden;">
        <table id="desktop" cellpadding="0" cellspacing="0" width="100%" border="1px solid black">
            <tr>
                <td  style="display: block; clear: both !important; margin: 0 auto !important; width: 600px !important; overflow: hidden;">
                    <table  border="0" cellspacing="0" width="100%" style="border-collapse: collapse;">

                        <tr style="">
                            <th>

                            </th>
                            <th style="padding-top: 20px;">
                                <span style="color: #504e4b;"/>
                                    example text                            
                                </span>
                            </th>
                        </tr>

                        <tr style="padding: 0; background: #ffffff; color: #504e4b;">
                            <td colspan="2">
                                <a href='#' style="cursor: default;"><img src="assets/example.gif" style="display: block;"></a>
                                <a href='#' style="cursor: default;"><img src="assets/example.gif" style="display: block; pointer-events: none; cursor: default;"></a>
                                <span style="display: block; font-size: 13px; font-weight: 200; text-transform: uppercase; margin-top: 20px; margin-bottom: 10px; padding-left: 30px; color: #f36b22;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 35px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px; padding-left: 30px;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 13px; font-weight: 200; padding-left: 30px; padding-bottom: 20px;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #ffffff;">
                            <td style="width: 50%; padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                            </td>
                            <td style="padding: 0px; border: none;">

                            </td>
                        </tr>

                        <tr style="height: 415px; color: #504e4b;">
                            <td style="padding: 0px; width: 50%; background-color: #fccb03; vertical-align: top;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                                <span style="display: block; height: 10px;"></span>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px; padding-left: 20px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 50px; font-weight: 200; color: #504e4b;">
                                    example text
                                </span>
                            </td>
                            <td style="padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.gif" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="vertical-align: top; color: #504e4b;">
                            <td style="width: 50%; padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                            </td>
                            <td style="text-align: right; padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block; padding-right: 20px;"></a>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 180px; margin-bottom: 10px; padding-right: 20px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 40px; font-weight: 200; color: #504e4b;">
                                    example text
                                </span>
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #f36b22; color: #ffffff;">
                            <td>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-bottom: 10px; padding-left: 30px; padding-top: 50px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 30px; padding-right: 20px; padding-bottom: 50px; font-weight: 200;">
                                    example text
                                </span>
                            </td>
                            <td style="padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #ffffff;">
                            <td style="padding: 0px; border: none;">

                            </td>
                            <td style="width: 50%; padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="color: #504e4b;">
                            <td align="center" colspan="2" style="padding: 20px 40px 20px 40px;">
                                <span style="display: block;">
                                    example text
                                </span>
                                <span style="display: block; padding: 20px 0px 20px 0px;">
                                    example text
                                </span>
                            </td>
                        </tr>


                    </table>
                </td>
            </tr>
        </table>


        <!-- mobile view -->
        <table id="mobile" border="1px solid #f2f2f2" cellpadding="0" cellspacing="0" style="width: 100%; max-width: 600px; margin: 0 auto;">
            <tr>
                <td align="center" style=" clear: both !important; margin: 0 auto !important; width: 100% !important; max-width: 450px !important; overflow: hidden; overflow-y: hidden;">
                    <table align="center" border="0" cellpadding="0" cellspacing="0" style=" border-collapse: collapse;">

                        <tr id="date">
                            <th style="padding-top: 20px;">example text</th>
                        </tr>

                        <tr>
                            <td align="center" style="padding: 0; overflow-x: hidden; vertical-align: middle;">
                                <img id="header" src="assets/example.gif" style="width: 100% !important; display: block !important;" />
                            </td>
                        </tr>

                        <tr>
                            <td align="center" style="padding: 0; overflow-x: hidden; vertical-align: middle;">
                                <img id="planter" src="assets/example.gif" style="width: 100% !important; display: block !important;" />
                            </td>
                        </tr>

                        <tr>
                            <td style="padding: 20px;">
                                <span style="display: block; font-size: 13px; font-weight: 200; text-transform: uppercase; margin-top: 20px; margin-bottom: 10px; color: #f36b22;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 35px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 13px; font-weight: 200; padding-bottom: 0px;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #ffffff;">
                            <td style="padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img id="trend-top" src="assets/example.png" style="display: block;"></a>
                            </td>
                        </tr>


                        <tr style="color: #504e4b;">
                            <td style="padding: 0px; width: 50%; background-color: #fccb03; vertical-align: top;">
                                <a href='#' style="cursor: default;"><img id="trend-bottom" src="assets/example.png" style="display: block;"></a>
                                <span style="display: block; height: 10px;"></span>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px; padding-left: 20px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 50px; font-weight: 200; color: #504e4b;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                <img id="trend-wheels" src="assets/example.gif" style="display: block; width: 100%;">
                            </td>
                        </tr>

                        <tr>
                            <td align="center" style="background: #ffffff;">
                                <img id="display-ideas" src="assets/example.png" style="max-width: 170px; display: block; width: 100%;">
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 30px; margin-bottom: 10px; padding-left: 20px; text-align: left;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 0px; font-weight: 200; color: #504e4b; text-align: left;">
                                    example text
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <img id="pot-stand" src="assets/example.png" style="display: block; margin: 0 auto; padding: 20px 0px 40px 0px; max-width: 300px; width: 90%">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr align="right" style="padding: 0; background: #f36b22; color: #ffffff;">
                            <td style="padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>
                        <tr align="right" style="padding: 0; background: #f36b22; color: #ffffff;">
                            <td>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-bottom: 10px; padding-left: 35px; text-align: left;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 30px; padding-right: 20px; padding-bottom: 50px; font-weight: 200; text-align: left;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr style="color: #504e4b;">
                            <td align="center" style="padding: 20px 40px 20px 40px;">
                                <span style="display: block;">
                                    example text
                                </span>
                                <span style="display: block; padding: 20px 0px 20px 0px;">
                                    example text
                                </span>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>


    </body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试将mso规则添加到隐藏和取消隐藏。您也可以使用基本断点,但我发现使用@media screen and (max-width:XXpx)也是一个更好的解决方案,因为大多数人不会随身携带宽度小于450像素的笔记本电脑。

电子邮件设计和开发纯粹是一个完全混合的包,我祝你好运。

总而言之,我不会采用这种方法隐藏和取消隐藏内容。 Outlook会完全忽略它,Gmail会(如你所知)做不可预测的事情。

这是指向我制作Email template的基本模板的链接,可能有所帮助。

&#13;
&#13;
<!DOCTYPE html>
<html>
    <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>

        <style>
		   #outlook a{
			padding:0;
		}
		.ReadMsgBody{
			width:100%;
		}
		body{
			width:100% !important;
			min-width:100%;
			-webkit-text-size-adjust:100%;
			-ms-text-size-adjust:100%;
			-webkit-font-smoothing: antialiased;
		}
		v*{
		   	behavior:url(#default#VML);
			display:inline-block;
		}
		.ExternalClass{
			width:100%;
		}
		td{
			border-collapse: collapse!important;
		}
		.ExternalClass,
		.ExternalClass p,
		.ExternalClass span,
		.ExternalClass font,
		.ExternalClass td,
		.ExternalClass div{
			line-height:100%;
		}
		a img{
			border:none;
		}
		a {
			text-decoration:none !important;
		}
		img{
			display:block;
			outline:none;
			text-decoration:none;
			border:none; 
			 -ms-interpolation-mode: bicubic;
		}
		table{
			border-spacing:0;
			border-collapse: collapse !important;
			mso-table-lspace:0pt;
			mso-table-rspace:0pt;
		}
        @media (min-width: 451px) {
            table#mobile {
                display: none !important;
			max-height: 0px;
			font-size: 0px;
			overflow: hidden;
			mso-hide: all;
            }
        }

        @media (max-width: 450px) {
            table#desktop {
               display: none !important;
			max-height: 0px;
			font-size: 0px;
			overflow: hidden;
			mso-hide: all;
            }

            table#mobile {
                display: inline !important;
            }
        }

        </style>

    </head>


    <body style="width: 100% !important; margin: 0; padding: 0; font-size: 13.5px; line-height: 1.4; font-family: Helvetica; overflow-x: hidden;">
        <table id="desktop" cellpadding="0" cellspacing="0" width="100%" border="1px solid black">
            <tr>
                <td  style="display: block; clear: both !important; margin: 0 auto !important; width: 600px !important; overflow: hidden;">
                    <table  border="0" cellspacing="0" width="100%" style="border-collapse: collapse;">

                        <tr style="">
                            <th>

                            </th>
                            <th style="padding-top: 20px;">
                                <span style="color: #504e4b;"/>
                                    example text                            
                                </span>
                            </th>
                        </tr>

                        <tr style="padding: 0; background: #ffffff; color: #504e4b;">
                            <td colspan="2">
                                <a href='#' style="cursor: default;"><img src="assets/example.gif" style="display: block;"></a>
                                <a href='#' style="cursor: default;"><img src="assets/example.gif" style="display: block; pointer-events: none; cursor: default;"></a>
                                <span style="display: block; font-size: 13px; font-weight: 200; text-transform: uppercase; margin-top: 20px; margin-bottom: 10px; padding-left: 30px; color: #f36b22;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 35px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px; padding-left: 30px;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 13px; font-weight: 200; padding-left: 30px; padding-bottom: 20px;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #ffffff;">
                            <td style="width: 50%; padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                            </td>
                            <td style="padding: 0px; border: none;">

                            </td>
                        </tr>

                        <tr style="height: 415px; color: #504e4b;">
                            <td style="padding: 0px; width: 50%; background-color: #fccb03; vertical-align: top;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                                <span style="display: block; height: 10px;"></span>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px; padding-left: 20px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 50px; font-weight: 200; color: #504e4b;">
                                    example text
                                </span>
                            </td>
                            <td style="padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.gif" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="vertical-align: top; color: #504e4b;">
                            <td style="width: 50%; padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                            </td>
                            <td style="text-align: right; padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block; padding-right: 20px;"></a>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 180px; margin-bottom: 10px; padding-right: 20px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 40px; font-weight: 200; color: #504e4b;">
                                    example text
                                </span>
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #f36b22; color: #ffffff;">
                            <td>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-bottom: 10px; padding-left: 30px; padding-top: 50px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 30px; padding-right: 20px; padding-bottom: 50px; font-weight: 200;">
                                    example text
                                </span>
                            </td>
                            <td style="padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #ffffff;">
                            <td style="padding: 0px; border: none;">

                            </td>
                            <td style="width: 50%; padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr style="color: #504e4b;">
                            <td align="center" colspan="2" style="padding: 20px 40px 20px 40px;">
                                <span style="display: block;">
                                    example text
                                </span>
                                <span style="display: block; padding: 20px 0px 20px 0px;">
                                    example text
                                </span>
                            </td>
                        </tr>


                    </table>
                </td>
            </tr>
        </table>


        <!-- mobile view -->
        <table id="mobile" border="1px solid #f2f2f2" cellpadding="0" cellspacing="0" style="width: 100%; max-width: 600px; margin: 0 auto;">
            <tr>
                <td align="center" style=" clear: both !important; margin: 0 auto !important; width: 100% !important; max-width: 450px !important; overflow: hidden; overflow-y: hidden;">
                    <table align="center" border="0" cellpadding="0" cellspacing="0" style=" border-collapse: collapse;">

                        <tr id="date">
                            <th style="padding-top: 20px;">example text</th>
                        </tr>

                        <tr>
                            <td align="center" style="padding: 0; overflow-x: hidden; vertical-align: middle;">
                                <img id="header" src="assets/example.gif" style="width: 100% !important; display: block !important;" />
                            </td>
                        </tr>

                        <tr>
                            <td align="center" style="padding: 0; overflow-x: hidden; vertical-align: middle;">
                                <img id="planter" src="assets/example.gif" style="width: 100% !important; display: block !important;" />
                            </td>
                        </tr>

                        <tr>
                            <td style="padding: 20px;">
                                <span style="display: block; font-size: 13px; font-weight: 200; text-transform: uppercase; margin-top: 20px; margin-bottom: 10px; color: #f36b22;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 35px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px;">
                                    example text
                                </span>
                                <span style="display: block; font-size: 13px; font-weight: 200; padding-bottom: 0px;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr style="padding: 0; background: #ffffff;">
                            <td style="padding: 0px; border: none;">
                                <a href='#' style="cursor: default;"><img id="trend-top" src="assets/example.png" style="display: block;"></a>
                            </td>
                        </tr>


                        <tr style="color: #504e4b;">
                            <td style="padding: 0px; width: 50%; background-color: #fccb03; vertical-align: top;">
                                <a href='#' style="cursor: default;"><img id="trend-bottom" src="assets/example.png" style="display: block;"></a>
                                <span style="display: block; height: 10px;"></span>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 10px; margin-bottom: 10px; padding-left: 20px;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 50px; font-weight: 200; color: #504e4b;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr>
                            <td>
                                <img id="trend-wheels" src="assets/example.gif" style="display: block; width: 100%;">
                            </td>
                        </tr>

                        <tr>
                            <td align="center" style="background: #ffffff;">
                                <img id="display-ideas" src="assets/example.png" style="max-width: 170px; display: block; width: 100%;">
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-top: 30px; margin-bottom: 10px; padding-left: 20px; text-align: left;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 20px; padding-right: 20px; padding-bottom: 0px; font-weight: 200; color: #504e4b; text-align: left;">
                                    example text
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <img id="pot-stand" src="assets/example.png" style="display: block; margin: 0 auto; padding: 20px 0px 40px 0px; max-width: 300px; width: 90%">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>

                        <tr align="right" style="padding: 0; background: #f36b22; color: #ffffff;">
                            <td style="padding: 0px;">
                                <a href='#' style="cursor: default;"><img src="assets/example.png" style="display: block;"></a>
                                <a href='#' style="cursor: default;"><img src="assets/example.png" align="right" style="display: block;"></a>
                            </td>
                        </tr>
                        <tr align="right" style="padding: 0; background: #f36b22; color: #ffffff;">
                            <td>
                                <span style="display: block; font-size: 28px; font-weight: 900; line-height: 1; text-transform: uppercase; margin-bottom: 10px; padding-left: 35px; text-align: left;">
                                    example text
                                </span>
                                <span style="display: block; padding-left: 30px; padding-right: 20px; padding-bottom: 50px; font-weight: 200; text-align: left;">
                                    example text
                                </span>
                            </td>
                        </tr>

                        <tr style="color: #504e4b;">
                            <td align="center" style="padding: 20px 40px 20px 40px;">
                                <span style="display: block;">
                                    example text
                                </span>
                                <span style="display: block; padding: 20px 0px 20px 0px;">
                                    example text
                                </span>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>


    </body>
</html>
&#13;
&#13;
&#13;