text-overflow: ellipsis in table-cell without width

后端 未结 7 792
后悔当初
后悔当初 2020-12-04 13:18

I\'m trying to achieve a responsive table width text-overflow: ellipsis; in the middle cell that looks like this:

| Button 1 | A one-lined text th

7条回答
  •  青春惊慌失措
    2020-12-04 13:57

    A cleaner way would be to simply set a max-width on the td.

    Based on @Fabrício Matté's reply,

    http://jsfiddle.net/V83Ae/89/

    And

    body { margin: 0; }
    
    .main-table {
        width: 100%;
    }
    
    .truncate {
        text-overflow: ellipsis;
        white-space  : nowrap;
        overflow     : hidden;
        max-width    : 100px; /* Can be any size, just small enough */
    }
    
    .nowrap {
        white-space: nowrap;
    }
    

    I have no idea why this works, but it does, so if someone can figure how why applying a max-width works then please let me know as I did it by accident.

    提交回复
    热议问题
    Button 1 Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus doloremque magni illo reprehenderit consequuntur quia dicta labore veniam distinctio quod iure vitae porro nesciunt. Minus ipsam facilis! Velit sapiente numquam. Button 2