Long word wrap in nested tables

后端 未结 3 564
予麋鹿
予麋鹿 2021-01-28 07:02

I\'m trying to wrap a long word. I have seen this post : How to prevent long words from breaking my div?

It works great in a simple case like this :

.wra         


        
相关标签:
3条回答
  • 2021-01-28 07:50

    I think this is what you are looking for.

    WORKING DEMO

    The HTML:

    <!-- This wraps correctly -->
    <div style="width:145px;">
        <div class="wrapWords" style="width:100%;">
            <a href="#">AAAAAAAAAAAAAAAAAA</a>
        </div>
    <div>
    
    <!-- This doesn't work -->
    <table style="width:100%;">
        <tr>
            <td style="width:145px;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:130px;">
                            <div class="wrapWords" style="width:inherit; display:inline-block;">
                                <a href="#">BBBBBBBBBBBBBBBBBB</a>
                            </div>
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </td>
            <td>
            </td>
        </tr>
    </table>
    

    The Logic:

    The div and td have different display characteristics. You need to make your div which is nested inside the td to change its display to, for instance here inline-block with a fixed width to achive what you are looking for.

    Hope this helps.

    0 讨论(0)
  • 2021-01-28 07:54

    There are 2 completely different algorithms for table layout: with or without table-layout: fixed

    Former will adapt width of cells to the author's will
    Latter will adapt width of cells to the content (the relative quantity/width/whatever of content in cells)

    0 讨论(0)
  • 2021-01-28 07:58

    table is taking the table-layout: auto; by default so as per contents increase the width also increases so you need to set table-layout to fixed.

    table{
        table-layout: fixed;
    }
    

    demo

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