Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i have elispsis on my table cell without using max-width?

I have the following table


    <table>
        <tr>
            <td>Long name name name name name name</td>
        </tr>
        <tr>
            <td>Some shorter</td>
        </tr>
    </table>

and my css

table {
    border: 1px solid black;
}

td {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

i needed to have elipsis on my table so that is why i used max-width: 100px; together with white-space: nowrap;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But the problem here is that i need my td to have fixed with

td {
    width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

if i do this than my td has fixed width but i lose the elipsis. Is there some way with which i can do this ?

>Solution :

Use table-layout:fixed;

table {
    border: 1px solid black;
    width:100%;
    table-layout:fixed;
}

td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
    <table>
        <tr>
            <td>Long name name name name name name Long name name name name name name Long name name name name name name Long name name name name name name Long name name name name name name</td>
        </tr>
        <tr>
            <td>Some shorter</td>
        </tr>
    </table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading