【问题标题】:Multi-line text values destroy the horizontal alignment of the layout多行文本值会破坏布局的水平对齐方式
【发布时间】:2018-09-11 13:46:48
【问题描述】:

在下面的代码中,当第一列的值超过一行时(在这种情况下是标题为“一个长值超过一行”的项),该列不再与其他两个对齐:

<table>
      <tr >
        <td valign="top" style="padding: 17px 19px 0; background-color: #ffffff; text-align: center;" >
          <table border="0" role="presentation" cellpadding="0" cellspacing="0" width="100%" style="border:0 !important;" align="center">
            <tr>
              <td width="100%" align="center" style="padding: 17px 0 0;">
                <h2 style="margin: 0; font-family: 'Playfair Display', Georgia, serif; font-style: italic; font-size: 25px; color: #E35E19; font-weight: 900;">Coming soon</h2>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <!-- 3 Even Columns : BEGIN -->
      <tr>
        <td valign="top" style="padding: 0 19px 17px; background-color: #ffffff; text-align: center;">
          <table border="0" role="presentation" cellpadding="0" cellspacing="0" width="100%" style="border:0 !important;">
            <tr>
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">a long value that exceeds one line</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">Lorem ipsum</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">Lorem ipsum</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
            </tr>
          </table>
        </td>
      </tr>
    </table>

我已经从不必要的标签中删除了代码。上面看到的代码位于一个单独的文件中,目前不是包含的 sn-p。

【问题讨论】:

  • 您真的应该使用类将CSSHTML 分开。这将使代码更容易处理。此外,据我所知,sn-p 工作正常。
  • @kabanus 开发人员在电子邮件的开头和 HTML 标记中都分别使用了 CSS。我希望代码尽可能接近原始代码。
  • 没问题,只是对阅读问题的任何人的一般性建议。

标签: html css html-email responsive


【解决方案1】:

默认的垂直对齐方式是居中,但你想要置顶:

tr {
    vertical-align: top;
}
<table>
      <tr >
        <td valign="top" style="padding: 17px 19px 0; background-color: #ffffff; text-align: center;" >
          <table border="0" role="presentation" cellpadding="0" cellspacing="0" width="100%" style="border:0 !important;" align="center">
            <tr>
              <td width="100%" align="center" style="padding: 17px 0 0;">
                <h2 style="margin: 0; font-family: 'Playfair Display', Georgia, serif; font-style: italic; font-size: 25px; color: #E35E19; font-weight: 900;">Coming soon</h2>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <!-- 3 Even Columns : BEGIN -->
      <tr>
        <td valign="top" style="padding: 0 19px 17px; background-color: #ffffff; text-align: center;">
          <table border="0" role="presentation" cellpadding="0" cellspacing="0" width="100%" style="border:0 !important;">
            <tr>
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">a long value that exceeds one line</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">Lorem ipsum</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">Lorem ipsum</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
            </tr>
          </table>
        </td>
      </tr>
    </table>

【讨论】:

  • 真的。但这将适用于所有&lt;tr&gt; 标签,对吗?否则,你就当场了。抱歉,我不得不选择其他答案。无论如何,谢谢你的时间。
【解决方案2】:

您必须在嵌套表中添加另一个valign='top'

JSFIDDLE

...
<tr valign='top'>
              <!-- Column : BEGIN -->
...

完整代码:

<table>
      <tr >
        <td valign="top" style="padding: 17px 19px 0; background-color: #ffffff; text-align: center;" >
          <table border="0" role="presentation" cellpadding="0" cellspacing="0" width="100%" style="border:0 !important;" align="center">
            <tr>
              <td width="100%" align="center" style="padding: 17px 0 0;">
                <h2 style="margin: 0; font-family: 'Playfair Display', Georgia, serif; font-style: italic; font-size: 25px; color: #E35E19; font-weight: 900;">Coming soon</h2>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <!-- 3 Even Columns : BEGIN -->
      <tr>
        <td valign="top" style="padding: 0 19px 17px; background-color: #ffffff; text-align: center;">
          <table border="0" role="presentation" cellpadding="0" cellspacing="0" width="100%" style="border:0 !important;">
            <tr valign='top'>
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">a long value that exceeds one line</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">Lorem ipsum</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
              <!-- Column : BEGIN -->
              <td width="33.33%">
                <table  cellspacing="0" cellpadding="0" border="0">
                  <tr>
                    <td  style="padding: 22px 11px 0px; text-align: center" >
                      <img src="http://placehold.it/170" width="163" height="163" alt="alt_text" border="0" class="fluid img221" style="vertical-align: middle; height: auto; background: #dddddd; font-family: sans-serif; font-size: 15px; color: #555555;">
                        </td>
                  </tr>
                  <tr>
                    <td  style="line-height: 20px; color: #000000; padding: 0; text-align: center;">
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 13px; line-height: 18px; font-weight: 700;">Lorem ipsum</p>
                      <p style="margin: 0; font-family: 'Roboto', Tahoma, sans-serif; font-size: 12px; line-height: 18px;"><i>Lorem ipsum</i></p>
                    </td>
                  </tr>
                </table>
              </td>
              <!-- Column : END -->
            </tr>
          </table>
        </td>
      </tr>
    </table>

【讨论】:

  • 非常感谢。不是前端的人,这让我整晚都睡不着。祝你有美好的一天!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-07
  • 2016-01-20
  • 2020-04-23
相关资源
最近更新 更多