CSS,使表最大宽度的100%

问题描述 投票:12回答:7

鉴于电子邮件模板如下:

<style>
  @import url("http://fonts.googleapis.com/css?family=Open Sans");
</style>

<div style="width:100%; background:#F2F2F2">
  <table style="padding: 25px; margin: 0 auto; font-family:'Open Sans', 'Helvetica', 'Arial';">
    <tr align="center" style="margin: 0; padding: 0;">
      <td>
        <table style="border-style:solid; border-width:2px; border-color: #c3d2d9;" cellspacing="0">
          <tr style="background-color: white;">
            <td style="width: 700px; padding: 10px 15px 10px 15px; color: #000000;">
              <p>Some content here</p>
              <span style="font-weight: bold;">My Signature</span><br/>
              My Title<br/>
              My Company<br/>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</div>

该表将是完全700像素宽是所需要的。然而,由于其完全固定的宽度,故不能在设备上具有小于700像素宽度调整大小。但是,如果我修改TD元素这样:

<td style="max-width: 700px; width: 90%; padding: 10px 15px 10px 15px; color: #000000;">
   <p>Some content here</p>
   <span style="font-weight: bold;">My Signature</span><br/>
   My Title<br/>
   My Company<br/>
</td>

那么该表只〜100像素宽。

我将如何重新排列CSS来让这个表是700像素,但调整大小视口变得越来越小?

css html-table width html-email
7个回答
17
投票

像这样

demo

CSS

table{
    width:100%;
}

4
投票

您需要使用:

    table{
        width:100%;
        table-layout: fixed;
        overflow-wrap: break-word;
    }

Demo


2
投票

我有同样的问题,这是由于我对造成它变得愚蠢显示表引导类“隐LG”:阻止重要的;

我不知道如何引导从未考虑过,只是,而不是这样做:

@media (min-width: 1200px) {
    .hidden-lg {
         display: none;
    }
}

然后只留下任何显示它之前,必须对其他screensizes ..也许是太先进的为他们找出元素..

反正这样:

table {
    display: table; /* check so these really applies */
    width: 100%;
}

应该管用


0
投票

最大宽度是绝对不能很好的支持。如果你要使用它,在你的风格标签使用它在媒体查询。 IOS,Android和Windows Phone的默认邮件都支持他们。 (Gmail和Outlook移动不)

http://www.campaignmonitor.com/guides/mobile/targeting/

看看星巴克的例子在底部


0
投票

我有max-width: 100%的表一个很好的工作液。只需使用word-break: break-all;的表格单元格(除标题单元格),打破所有的长文成几行:

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

table {
  max-width: 100%; 
}
table td {
  word-break: break-all;
}

</style>
</head>
<body>

<table border="1">
  <tr>
    <th><strong>Input</strong></th>
    <th><strong>Output</strong></th>
  </tr>
  <tr>
    <td>some text</td>
    <td>12b6459fc6b4cabb4b1990be1a78e4dc5fa79c3a0fe9aa9f0386d673cfb762171a4aaa363b8dac4c33e0ad23e4830888</td>
  </tr>
</table>

</body>
</html>

这将使得这样的(当屏幕宽度被限制):


0
投票

我不得不使用:

table, tbody {
    width: 100%;
}

单单table是不够的,还需要在tbody它为我工作。


-2
投票

用这个 :

<div style="width:700px; background:#F2F2F2">
    <table style="width:100%;padding: 25px; margin: 0 auto; font-family:'Open Sans', 'Helvetica', 'Arial';">
        <tr align="center" style="margin: 0; padding: 0;">
            <td>
                <table style="width:100%;border-style:solid; border-width:2px; border-color: #c3d2d9;" cellspacing="0">
                    <tr style="background-color: white;">
                        <td style=" padding: 10px 15px 10px 15px; color: #000000;">
                            <p>Some content here</p>
                            <span style="font-weight: bold;">My Signature</span><br/>
                            My Title<br/>
                            My Company<br/>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.