【问题标题】:is there an alternitive to display: grid that is supported for gmail and/or outlook?是否有替代显示:gmail 和/或 Outlook 支持的网格?
【发布时间】:2021-09-12 11:11:18
【问题描述】:

我为自己成功地为客户制作了我想要的自定义网格感到非常自豪,但后来我被告知它也需要用于电子邮件。尝试寻找不同的显示替代方案:网络上的网格,但找不到。

是否存在这样的替代方案?如果没有,有什么建议?

这里是我制作的网格供参考:

<!DOCTYPE html>
<html>
<head>
<style>

.wrapper {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 10px;
  grid-auto-rows: minmax(30px, auto);
  
  
}
.one {
  grid-column: 1 / 16;
  grid-row: 1 / 9;
  background-color: black;
}
.two {
  grid-column: 16 / 21;
  grid-row: 1 / 9;
  background-color: red;
}
.three {
  grid-column: 1/7;
  grid-row: 9 / 12;
  background-color: green;
}
.four {
  grid-column: 15/21;
  grid-row: 9/12;
  background-color: blue;
}
.five {
  grid-column: 1/11;
  grid-row: 12/17;
  background-color: yellow;
}
.six {
  grid-column: 11/21;
  grid-row: 12/17;
  background-color: purple;
}
.seven {
  grid-column: 7/15;
  grid-row: 9/12;
  background-color: gray;
}


</style>
</head>
<body>

<div class="wrapper">
  <div class="one">One</div>
  <div class="two">Two</div>
  <div class="three">Three</div>
  <div class="four">Four</div>
  <div class="five">Five</div>
  <div class="six">Six</div>
  <div class="seven">text</div>
</div>


</body>
</html>

【问题讨论】:

    标签: html css gmail css-grid html-email


    【解决方案1】:

    CSSHead-Style 的支持对于大约 45% 的电子邮件来说非常差
    citatation: CSS support

    所以总体而言,在设计电子邮件模板时,您应该转发 inline-style

    CSS-Grid(支持约 59%)和Flexbox(支持约 59%)都没有来自电子邮件客户端的合理支持。
    citatation: CSS-Grid support
    citatation: Flexbox support

    您唯一能做的就是使用&lt;table&gt;,因为它是一个 HTML 解决方案,所以它具有可靠的 100% 支持。它不是表格数据,而是可接受的电子邮件模板,因为它是唯一完全受支持的方法!
    citatation: table support

    电子邮件模板:

    如上所述,我们必须使用表格。相当于grid-gap 将是border-collapse: seperate; + border-spacing: value; 直接用于表本身的组合:&lt;table style="border-collapse: seperate; border-spacing: 10px;"&gt;

    为了模拟你的 grid-template-columns: repeat(20, 1fr);,我从一个空的 &lt;tr&gt; 开始,它有 20 倍 &lt;td width="5%"&gt;

    这现在允许我们使用 colspan-attribute 来跨越多个列,就像 grid-column: spanX 一样

    要模拟最小高度,您只需应用height-attribute,它与表格的min-height 相同,因为如果内容较大,表格单元格将调整大小。我只是将你想要跨越的行数乘以 30px。

    要使文本从左上角而不是表格单元格的中心开始,您必须将text-align:left; vertical-align:top; 应用于每个&lt;td&gt;

    <table width="100%;" style="border-collapse: seperate; border-spacing: 10px;">
      <tr>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
        <td width="5%;"></td>
      </tr>
      <tr height="240px">
        <td colspan="15" style="background-color:black; color:white; text-align:left; vertical-align:top;">one</td>
        <td colspan="5" style="background-color:red; text-align:left; vertical-align:top;">two</td>
      </tr>
      <tr height="90px">
        <td colspan="6" style="background-color:green; text-align:left; vertical-align:top;">three</td>
        <td colspan="8" style="background-color:gray; text-align:left; vertical-align:top;">text</td>
        <td colspan="6" style="background-color:blue; text-align:left; vertical-align:top;">four</td>
      </tr>
      <tr height="150px">
        <td colspan="10" style="background-color:yellow; text-align:left; vertical-align:top;">five</td>
        <td colspan="10" style="background-color:purple; text-align:left; vertical-align:top;">six</td>
      </tr>
    </table>

    【讨论】:

    • 这是一个很好的等价物——但请注意它在手机上的外观。一旦被压扁,可能没有足够的空间:litmus.com/checklist/emails/public/ded6145
    • @Nathan 是的,但是同样的规则适用于真正的网格,这就是您通常有媒体查询的内容。出于这个确切原因,电子邮件模板应该是简约的,这是概念性的。因此,它适用于评论网站,但不适用于所提出的实际问题。
    猜你喜欢
    • 2019-05-11
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 2011-01-16
    • 2014-10-22
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    相关资源
    最近更新 更多