Table overflowing outside of div

后端 未结 9 2072
鱼传尺愫
鱼传尺愫 2020-11-30 00:17

I\'m trying to stop a table that has width explicitly declared from overflowing outside of its parent div. I presume I can do this in some way using max-w

相关标签:
9条回答
  • 2020-11-30 00:36

    You may try this CSS. I have experienced it working always.

    div {
      border-style: solid;
      padding: 5px;
    }
    
    table {
      width: 100%;
      word-break: break-all;
      border-style: solid;
    }
    <div style="width:200px;">
      <table>
        <tr>
          <th>Col 1</th>
          <th>Col 2</th>
          <th>Col 3</th>
          <th>Col 4</th>
          <th>Col 5</th>
        </tr>
        <tr>
          <td>data 1</td>
          <td>data 2</td>
          <td>data 3</td>
          <td>data 4</td>
          <td>data 5</td>
        </tr>
        <table>
    </div>

    0 讨论(0)
  • 2020-11-30 00:38

    I tried all the solutions mentioned above, then did not work. I have 3 tables one below the other. The last one over flowed. I fixed it using:

    /* Grid Definition */
    table {
        word-break: break-word;
    }
    

    For IE11 in edge mode, you need to set this to word-break:break-all

    0 讨论(0)
  • 2020-11-30 00:43

    A crude work around is to set display: table on the containing div.

    0 讨论(0)
  • 2020-11-30 00:49
    overflow-x: auto;
    overflow-y : hidden;
    

    Apply the styling above to the parent div.

    0 讨论(0)
  • 2020-11-30 00:50

    You can prevent tables from expanding beyond their parent div by using table-layout:fixed.

    The CSS below will make your tables expand to the width of the div surrounding it.

    table 
    {
        table-layout:fixed;
        width:100%;
    }
    

    I found this trick here.

    0 讨论(0)
  • 2020-11-30 00:50

    There's a width="400" on the table, remove it and it will work...

    0 讨论(0)
提交回复
热议问题