text-overflow: ellipsis in table-cell without width

后端 未结 7 773
后悔当初
后悔当初 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 14:05

    Set your 100% width on the table and specify a fixed table-layout:

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

    Then, set the following for whichever table cell should have the ellipsis:

    td:nth-child(2) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    

    Voila! Responsive table with an ellipsis overflow!

    Demo: http://jsfiddle.net/VyxES/

提交回复
热议问题