Outlook 的电子邮件问题

Email Issue with Outlook

我在 Outlook 中编码块时遇到问题。

我试图在桌面上只显示一个块,在移动设备上只显示一个块,并且使用了 类 和媒体查询。我知道 Outlook 存在媒体查询问题,所以这可能是我 运行 遇到麻烦的地方。

这是我的代码,它在浏览器中运行良好,但是,当我在 Outlook 中预览时,当在较大(桌面)版本中预览时,它会同时显示桌面版和移动版:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta name="format-detection" content="telephone=no">
    <style type="text/css">

    @media screen and (max-width: 599px) {
        .mobile-hide {
            display:none !important;
            visibility:hidden !important;
            height:0 !important;
            overflow:hidden !important;
            font-size:0 !important;
            line-height:0 !important;
            padding:0;
            max-height:0;
            width:0 !important;
        }
        .mobile-show {
            display: block!important;
        }

    }

@media screen and (min-width: 600px) {

.desktop-hide{

    display:none;

    }

}

</style>
</head>



<body>

<table border="0" cellpadding="0" cellspacing="0">


                                     <tr class="mobile-hide">
                                        <td width="10">&nbsp;</td>
                                        <td colspan="4" align="center">
                                            <p style="font-family:Verdana,sans-serif;font-size:20px;color:#393939;text-align:left;margin-bottom:0;margin-top:0;line-height:20px;font-weight: bold;">
    <span style="font-size:14px;color:white;padding:10px;background-color:lightblue;" bgcolor="lightblue">Test</span><br><br>
                                               <img style = "display: block!important;margin: 0 auto;" src="https://via.placeholder.com/50x50">
                                            </p>
                                        </td>
                                        <td colspan="2" align="left" style="padding:20px;">
                                            <p style="font-family:Verdana,sans-serif; color:#393939;text-align:left;margin-bottom:0;margin-top:0;line-height:20px;font-weight: bold;padding-left: :10px;">
                                                <h2>Test Your Page</h2>
                                                This is some test content to demonstrate the structure of how the page might be built. It is a test paragraph with a bit of content displayed and a smail bit of code attached.
                                            </p>
                                        </td>
                                        <td width="30" style="padding:10px;"><b>Right</b>
                                        </td>
                                    </tr>


                                    <tr class = "desktop-hide">

                                        <td colspan="8">
                                            <table class="mobile-width" width="100%" border="0" cellpadding="0" cellspacing="0">
                                                <tr><td colspan ="2">Test Your Page <span style = "padding-left:30px;">Right</span></td></tr>
                                                <tr><td><img style = "display: block!important;margin: 0 auto;" src="https://via.placeholder.com/50x50"></td><td>This is some test content to demonstrate the structure of how the page might be built. It is a test paragraph with a bit of content displayed and a smail bit of code attached.</td></tr>
                                            </table>
                                        </td>
                                    </tr>



</table>



</body>
</html>

如果有人能帮助我完成这项工作,那就太好了,这样在 Outlook 中预览时只会显示一个,具体取决于显示的是桌面视图还是移动视图

我仍然认为尝试使用支持不佳的技术是愚蠢的,但以下可能可行。

首先使用移动设备。应用将影响移动 外部 媒体查询的样式。这意味着如果不支持媒体查询,这是您的默认样式。在媒体查询中应用您的桌面样式,如果不支持媒体查询,应该忽略它。

/*Go Mobile First - This will happen if media queries are supported or not*/
  .mobile-hide {
    display: none;   
  }


/*This will work where supported and be ignored where not
  I.E. Outlook will always display the mobile version
*/
@media screen and (min-width: 600px) {
  .desktop-hide {
    display: none;
  }
  
  .mobile-hide {
    display: table-row;   
  }
}
<table border="0" cellpadding="0" cellspacing="0">
  <tr class="mobile-hide">
    <td width="10">&nbsp;
    </td>
    <td colspan="4" align="center">
      <p style="font-family:Verdana,sans-serif;font-size:20px;color:#393939;text-align:left;margin-bottom:0;margin-top:0;line-height:20px;font-weight: bold;"><span style="font-size:14px;color:white;padding:10px;background-color:lightblue;" bgcolor="lightblue">Test</span><br><br><img style="display: block!important;margin: 0 auto;" src="https://via.placeholder.com/50x50"></p>
    </td>
    <td colspan="2" align="left" style="padding:20px;">
      <p style="font-family:Verdana,sans-serif; color:#393939;text-align:left;margin-bottom:0;margin-top:0;line-height:20px;font-weight: bold;padding-left: :10px;">
        <h2>Test Your Page</h2>This is some test content to demonstrate the structure of how the page might be built. It is a test paragraph with a bit of content displayed and a smail bit of code attached. </p>
    </td>
    <td width="30" style="padding:10px;"><b>Right</b></td>
  </tr>
  <tr class="desktop-hide">
    <td colspan="8">
      <table class="mobile-width" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td colspan="2">Test Your Page <span style="padding-left:30px;">Right</span></td>
        </tr>
        <tr>
          <td><img style="display: block!important;margin: 0 auto;" src="https://via.placeholder.com/50x50"></td>
          <td>This is some test content to demonstrate the structure of how the page might be built. It is a test paragraph with a bit of content displayed and a smail bit of code attached.</td>
        </tr>
      </table>
    </td>
  </tr>
</table>

同时避免使用 !important 在这种情况下它会使媒体查询更难应用。