【问题标题】:How to do responsive text overflow with css?如何用css做响应式文本溢出?
【发布时间】:2017-02-02 22:39:01
【问题描述】:

我正在尝试创建一个类似于 Gmail 电子邮件列表的列表。 有一个td 会收到很长的文本。我想隐藏超出td宽度的文字。

我正在尝试这个:

JsFiddle

<table class="table">
<tr style="width: auto;">
    <td>Solicitante</td>
    <td>Tipo</td>
    <td style="text-overflow: clip; overflow: visible; white-space: nowrap;">Este é um resumo bem maior que o de baixo, para ser testado sassasa</td>
    <td>10/12/2014</td>
</tr>
  <tr style="width: auto;">
    <td>Solicitante</td>
    <td>Tipo</td>
    <td style="text-overflow: clip; overflow: hidden;">Este é um resumo bla bla bla bla bla bla bla</td>
    <td>10/12/2014</td>
</tr>

使用white-space: nowrap;,表格会比 boxview 大。如果我删除white-space: nowrap;,则溢出文本继续成行。 如何在响应式表格中隐藏溢出文本?谢谢

【问题讨论】:

    标签: html css twitter-bootstrap html-table


    【解决方案1】:

    您需要使用table-layout:fixed; + width 来控制tabletd 的最大宽度。 示例:500px 的表和您的 td 以 50% 溢出。

    <table class="table" style="
            table-layout:fixed;
            width:500px;/* any value-unit */
    ">
        <tr style="">
            <td>Solicitante</td>
            <td>Tipo</td>
            <td style="
                    width:50%;/* any value-unit */
                    text-overflow: ellipsis; /* draw dots */
                    overflow: hidden; 
                    white-space: nowrap;
    ">Este é um resumo bem maior que o de baixo, para ser testado sassasa</td>
            <td>10/12/2014</td>
        </tr>
        <tr style="width: auto;">
            <td>Solicitante</td>
            <td>Tipo</td>
            <td>Este é um resumo</td>
            <td>10/12/2014</td>
        </tr>
    </table>
    

    DEMO

    【讨论】:

    • 谢谢。但是让我做一点更正:而不是width: 500px,我使用width: 100% 来保持响应!谢谢
    • 一旦您了解了表格布局的目的及其用途,一切都取决于您,做任何适合您需要的事情 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多