text-overflow: ellipsis in table-cell without width

后端 未结 7 795
后悔当初
后悔当初 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:49

    After banging my head for hours, with no solution that worked, finally found it.

    The element you want for the base of the overflow nees a min/max width, where the max is inferior to the min width. You can then overflow the lement or a child of it, where you can set the with whatever way you choose: %, px, auto.

    I tried it in more than one tricky situation and it works on all.

    I'll try to post a fiidle with my examples but this should help you going.

    /* Apply on base element for proper overflow */
    max-width: 1px;
    min-width: 10000px;
    
    /* Apply on self or child, according to need */
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    

提交回复
热议问题