【问题标题】:how to set 2 buttons in 2 tables 1 under the other on mobile , html django templating如何在移动设备上的另一个下设置 2 个表 1 中的 2 个按钮,html django 模板
【发布时间】:2023-03-31 10:08:01
【问题描述】:

我的 html 将通过电子邮件服务作为电子邮件发送。因此它将在 gmail、yahoo 邮件、outlook 等中读取/显示。 这就是为什么我不能使用 inline-flex。 (我尝试使用 max-width 制作类,但它们被忽略了)。 这是我的文件中的内容,我在需要的地方包括了:

<table width="100%" cellpadding="0" cellspacing="0" border="0" class="container" bgcolor="#ffffff" align="center">
    <tr>
        <td align="left" style="width: 180px;min-width: 50%;max-width: 100%">
            <div align="center" style="font-family: 'Lato', sans-serif; font-size: 14px; border-radius: 6px; color: #ffffff;line-height:15px;background-color: #24b646;width: 180px;padding: 0px 10px 0px 10px;margin: 30px 0 30px 60px; height: 45px;" class="mobileWidth100 mobilePadding0">
                <a width="auto" href="{{extra.manage_team}}" target="_blank" alias="" style="font-family: 'Lato', sans-serif; text-decoration: none; color: #ffffff;font-weight:bold; letter-spacing:1px;height: 45px;line-height: 15px;vertical-align: middle;display:table-cell;">{% trans 'Manage Team'%}</a>
            </div>
        </td>
        <td align="left" style="width: 180px;min-width: 50%;max-width: 100%">
            <div align="center" style="font-family: 'Lato', sans-serif; font-size: 14px; border-radius: 6px; color: #ffffff; border: 1px solid #24b646; line-height:15px;background-color: #ffffff;width: 180px;padding: 0px 10px 0px 10px;height: 45px;">
                <a width="auto" href="{{extra.billing_overview}}" target="_blank" alias="" style="font-family: 'Lato', sans-serif; text-decoration: none; color: #24b646; font-weight:bold; letter-spacing:1px;height: 45px;line-height: 15px;vertical-align: middle;display:table-cell;">{% trans 'Billing Overview'%}</a>
            </div>
        </td>
    </tr>
</table>

这是它在桌面上的外观,部分还可以(我需要将第一个按钮更靠左):

这就是它在移动设备上的外观,如您所见,明显损坏:

我只想让 1 个对象彼此靠近,然后在移动设备上,第二个向下,并且两者的宽度都与它们的父对象相同

【问题讨论】:

  • 您可以使用 html 框架(如 Bootstrap)类或在您的 css 文件中使用媒体查询来执行此操作。 @media (max-width:768px){...}
  • 就像我说的,这是用于 django 模板的,这意味着这个 html 是作为电子邮件发送的。电子邮件客户端删除类。我尝试使用类,但它们只是被忽略并且没有任何反应。也许我的标题不清楚,所以我也编辑了我的回复
  • 我不认为你可以用电子邮件做到这一点,因为你需要使用媒体查询,并且它们在电子邮件客户端中没有得到广泛支持(尽管我找不到支持的最新客户端列表他们)
  • 这与 django 模板无关 - 你会得到完全相同的结果,但是生成的 HTML(包括纯静态 HTML)。
  • @ArthurM - 这是用于 HTML 电子邮件,而不是网站。这不能使用引导程序。

标签: css html-table html-email display


【解决方案1】:

请注意,您应该有一个 Lato 的备用字体,它不适用于 Outlook、Gmail 或其他一些不支持网络字体的电子邮件客户端。

如果您的按钮文本有两行,您将需要重新配置它以使其在 Outlook 中看起来不错。一个按钮永远不需要两行。这是一个很好的模板,可以帮助您继续前进。

首先,您需要一个媒体查询:

<style>
  @media screen and (max-width: 600px) {
    .stack-in-mobile {
      display: block !important;
      width: 100% !important;
      max-width: 100% !important;
    }
  }
</style>

接下来,您需要一个表格容器来存放您的电子邮件。

这个示例是一个非常简单的两个按钮表,反映了您想要的内容。我调整了填充,使它们的大小大致相同。

<table>
  <tr>
    <td class="stack-in-mobile">
      <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="margin: auto;">
        <tr>
          <td style="border-radius: 6px; background: #24b646;">
            <a href="#" target="_blank" style="background: #24b646; border: 1px solid #24b646; font-family: sans-serif; font-weight: bold; font-size: 14px; line-height: 15px; text-decoration: none; padding: 13px 22px; color: #ffffff; display: block; border-radius: 6px; letter-spacing: 1px;">Manage Team</a>
          </td>
        </tr>
      </table>
    </td>
    <td class="stack-in-mobile">
      <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="margin: auto;">
        <tr>
          <td style="border-radius: 6px; background: #ffffff;">
            <a href="#" target="_blank" style="background: #ffffff; border: 1px solid #24b646; font-family: sans-serif; font-weight: bold; font-size: 14px; line-height: 15px; text-decoration: none; padding: 13px 12px; color: #24b646; display: block; border-radius: 6px; letter-spacing: 1px;">Billing Overview</a> 
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>

剩下的部分由你来设计。

祝你好运。

【讨论】:

  • 这会起作用,我知道 OP 没有说明他/她支持哪些设备,但如果 td 必须是 th 才能在 Android 4 及更低版本上运行。
  • @Syfer 该按钮适用于 Android 4.4,但不会堆叠。堆栈与 Andoid 6 和目前的 IOS Outlook for 11 是相同的问题。如果我说我用 Donut、Froyo 或 Honeycomb 测试了这个,我会撒谎。我不确定我能想出一个比说我在 Froyo 中测试了一些东西更荒谬的说法。
  • 我不需要在特定设备上进行测试。不能使用 chrome、firefox 或其他。我需要能够在邮件客户端中看到这一点。现在@media 在桌面上工作。但是在手机版上,Gmail 和 Ymail 会忽略来自媒体的课程,所以我无法为移动版或桌面版设置不同的代码 :(
【解决方案2】:

也许是个愚蠢的问题 但是您是否使用了外部 css 源?并且很多 CSS 不能用于电子邮件模板。这是来自我制作的模板,应该适用于您的用例。

<html>
<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 " />
    <meta name="format-detection" content="telephone=no"/>
    <style type="text/css">
        body { margin: 0; padding: 0; -webkit-text-size-adjust: 100% !important; -ms-text-size-adjust: 100% !important; -webkit-font-smoothing: antialiased !important; font-family: 'ubuntu', Helvetica, Arial, sans-serif; }
        table { border-collapse: collapse; mso-table-lspace: 0px; mso-table-rspace: 0px;}
        .table-button a:visited { color: #fff; }
        .table-button a:hover { text-decoration: underline; }
        .no_m { margin: 0px;}
        @media only screen and (min-width:481px) and (max-width:649px) {
            .em_main_table { width: 100% !important; }
            .em_wrapper { width: 100% !important; }
            .em_hide { display: none !important; }
            .em_full_img { width: 100% !important; height: auto !important; }
            .em_center { text-align: center !important; }
           
            .em_h20 { height: 20px !important; }
            .em_ptop { padding-top: 20px !important; }
            .em_pbottom { padding-bottom: 20px !important; }
            .em_pad1 { padding: 20px 10px !important; }
            .header1_pad { padding: 0px 10px 20px 0px !important; }
            .em_hauto { height: auto !important; }
            .dimensions_30012018 { width: 100% !important; height: auto !important; }
            .em_data-tablet { display: table-cell !important; }
        }
        @media screen and (max-width: 649px) {
            .em_block { display: table-row !important; }
            .top-half { width: 50% !important;}
            .mobile_button { width: 100% !important; display: inline-block !important; padding: 5px 0px !important;}
        }
        @media screen and (max-width: 480px) {
            .em_main_table { width: 100% !important; }
            .em_wrapper { width: 100% !important; }
            .em_hide { display: none !important; }
            .em_center { text-align: center !important; }
            .em_hide1 { display: none !important; }
        }
    </style>
</head>
<body class="em_body" style="margin:0px; padding:0px;" bgcolor="#f3f8fc">
<table role="presentation" class="em_wrapper" align="center" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td align="center" valign="top">
            <table role="presentation" align="center" width="650" border="0" cellspacing="0" cellpadding="0" class="em_main_table" style="width:650px; table-layout:fixed;" bgcolor="#f3f8fc">

                <tr>
                <td mc:edit="zorgexpert" valign="top" align="center" style="padding:35px 25px 35px 25px; background-color:#ffffff;" class="em_pad1" bgcolor="#ffffff">
                    <table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
                        <tbody>
                            <tr>
                                <td align="center" class="em_black em_m_l" colspan="2" style="font-family:ubuntu, Helvetica, Arial, sans-serif;font-size:14px;line-height:22px;color:#333333;padding:11px 0px 19px;" valign="top">
                                    <table role="presentation"  align="left" border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%">
                                        <tr>
                                            <td colspan="2" align="center">
                                                <table role="presentation" class="em_wrapper" align="center" border="0" cellpadding="0" cellspacing="0">
                                                    <tr>
                                                        <td class="mobile_button">
                                                            <a class="em_link_nu" href="" style="mso-line-height-rule:exactly;color:#fff;text-decoration:none;font-weight:700;display:block;font-family:Verdana, sans-serif;font-size:14px;line-height:20px;" target="_blank">
                                                                <table role="presentation" width="240" border="0" cellspacing="0" cellpadding="0" bgcolor="#F2922C" align="left" style="width:240px;background-color:#04A0DA;border-radius:6px;" class="table-button table-button-bl em_wrapper">
                                                                    <tr>
                                                                        <td align="center" class="em_white" height="41" style="border-collapse:collapse;mso-line-height-rule:exactly;" valign="middle">
                                                                             <span class="em_white" style="color: #ffffff; text-decoration: none;">
                                                                                 Button
                                                                             </span>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </a>
                                                        </td>
                                                        <td height="10" width="10px" class="em_hide" style="height:10px; width:10px; line-height:0px; font-size:0px;">&nbsp;</td>
                                                        <td class="mobile_button">
                                                            <a class="em_link" href="" style="mso-line-height-rule:exactly;color:#fff;text-decoration:none;font-weight:700;display:block;font-family:Verdana, sans-serif;font-size:14px;line-height:20px;" target="_blank">
                                                                <table role="presentation" width="240" border="0" cellspacing="0" cellpadding="0" bgcolor="#F2922C" align="left" style="width:240px;background-color:#F2922C;border-radius:6px;" class="table-button table-button-or em_wrapper">
                                                                    <tr>
                                                                        <td align="center" class="em_white" height="41" style="border-collapse:collapse;mso-line-height-rule:exactly;" valign="middle">
                                                                             <span class="em_white" style="color: #ffffff; text-decoration: none;">
                                                                                 Button
                                                                             </span>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </a>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </table>
    </td>
</tr>
</table>
</body>

【讨论】:

【解决方案3】:

这就是在所有这些尝试之后使它起作用的原因:

 <table cellpadding="0" cellspacing="0" border="0" class="container" bgcolor="#ffffff" align="center" style="overflow-x:auto;margin: 30px 60px 0px 60px; width: calc(100% - 120px);">
<tr>
    <td>
      <table style="display: inline-block; vertical-align: middle; margin-right: 5px; margin-bottom: 20px;">
        <tr>
          <td
            align="left"
            style="width: 180px;min-width: 50%;max-width: 100%"
          >
            <div
              align="center"
              style="font-family: 'Lato', sans-serif; font-size: 14px; border-radius: 6px; color: #ffffff;line-height:15px;background-color: #24b646;width: 180px;padding: 0px 10px 0px 10px;height: 45px;"
            >
              <a
                width="auto"
                href="{{ extra.manage_team }}"
                target="_blank"
                alias=""
                style="font-family: 'Lato', sans-serif; text-decoration: none; color: #ffffff;font-weight:bold; letter-spacing:1px;height: 45px;line-height: 15px;vertical-align: middle;display:table-cell;"
                >{% trans 'Manage Team'%}</a
              >
            </div>
          </td>
        </tr>
      </table>

      <table style="display: inline-block; vertical-align: middle;margin-bottom: 20px;">
        <tr>
          <td
            align="left"
            style="width: 180px;min-width: 50%;max-width: 100%"
          >
            <div
              align="center"
              style="font-family: 'Lato', sans-serif; font-size: 14px; border-radius: 6px; color: #ffffff; border: 1px solid #24b646; line-height:15px;background-color: #ffffff;width: 180px;padding: 0px 10px 0px 10px;height: 45px;"
            >
              <a
                width="auto"
                href="{{ extra.billing_overview }}"
                target="_blank"
                alias=""
                style="font-family: 'Lato', sans-serif; text-decoration: none; color: #24b646; font-weight:bold; letter-spacing:1px;height: 45px;line-height: 15px;vertical-align: middle;display:table-cell;"
                >{% trans 'Billing Overview'%}</a
              >
            </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多