Table overflowing outside of div

后端 未结 9 2073
鱼传尺愫
鱼传尺愫 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:51

    Turn it around by doing:

    <style type="text/css">
      #middlecol {
        border-right: 2px solid red;
        width: 45%;
      }
    
      #middlecol table {
        max-width: 400px;
        width: 100% !important;
      }
    </style>
    

    Also I would advise you to:

    • Not use the center tag (it's deprecated)
    • Don't use width, bgcolor attributes, set them by CSS (width and background-color)

    (assuming that you can control the table that was rendered)

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

    I tried almost all of above but did not work for me ... The following did

    word-break: break-all;
    

    This to be added on the parent div (container of the table .)

    0 讨论(0)
  • 2020-11-30 01:01

    At first I used James Lawruk's method. This however changed all the widths of the td's.

    The solution for me was to use white-space: normal on the columns (which was set to white-space: nowrap). This way the text will always break. Using word-wrap: break-word will ensure that everything will break when needed, even halfway through a word.

    The CSS will look like this then:

    td, th {
        white-space: normal; /* Only needed when it's set differntly somewhere else */
        word-wrap: break-word;
    }
    

    This might not always be the desirable solution, as word-wrap: break-word might make your words in the table illegible. It will however keep your table the right width.

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