代码之家  ›  专栏  ›  技术社区  ›  Entretoize

max width对表没有任何作用

  •  1
  • Entretoize  · 技术社区  · 8 年前

    如果我设置这样的表格样式:

        table {
         width: 537px;
         height: 19px;
         max-width:  100%; 
        }
    <table>
      <tr>
        <td style="background-color: #ffe129;">text</td>
        <td style="background-color: #bdff4d;">text</td>
      </tr>
    </table>

    那么桌子的宽度是 537px 即使我的窗口宽度是400px。 400px .

    添加 display:block 到表格样式打断表格: see here

    1 回复  |  直到 8 年前
        1
  •  3
  •   Adel Elkhodary    8 年前

    我来定义 max-width: 537px; 例如,然后给出 width: 100% max-width 是什么 537像素 如果你说 width:100% 关于屏幕的宽度 不会超过 537像素

    table
    {
     width: 100%;
     height: 19px;
     max-width:  537px; 
    }
    <table>
    <tr>
    <td style="background-color: #ffe129;"></td>
    <td style="background-color: #bdff4d;"></td>
    </tr>
    </table>