html - 当文本内容太长时,列宽超过行宽

标签 html css ionic-framework

我有一行包含 3 列:第一列和最后一列设置为 size: auto 属性,第二列占用剩余的可用空间:

<ion-grid>
    <ion-row nowrap justify-content-center align-items-center>
        <ion-col size="auto">
            <p>I</p>
        </ion-col>
        <ion-col class="long-text">
            <p>A text that makes this column exceeds the width of the row</p>
        </ion-col>
        <ion-col size="auto">
            <p>III</p>
        </ion-col>
    </ion-row>
</ion-grid>

然后,为了剪切长文本,我使用了以下 scss 代码:

ion-grid {
    ion-row {
        ion-col {
            &.long-text {
                p { 
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                }
            }
        }
    }
}

但这似乎不起作用,包含长文本的列会拉伸(stretch)与文本的宽度一样长,并超过其父行的宽度

我正在寻找一种方法,当文本占用太多空间时,显示文本末尾的三个点,同时保留行内的所有列。

最佳答案

通过直接将文本传递到 ion-col 而不将其包装在另一个元素中,解决了我的问题:

<ion-grid>
    <ion-row nowrap justify-content-center align-items-center>
        <ion-col size="auto">
            <p>I</p>
        </ion-col>
        <ion-col class="long-text">
            A text that makes this column exceeds the width of the row
        </ion-col>
        <ion-col size="auto">
            <p>III</p>
        </ion-col>
    </ion-row>
</ion-grid>
ion-grid {
    ion-row {
        ion-col {
            &.long-text {
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
        }
    }
}

关于html - 当文本内容太长时,列宽超过行宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57228423/

相关文章:

html - html/css 中是否有裁剪图像的功能?

ios - ionic ios 应用程序开发

javascript - 如何将 Angular 应用程序连接到您的 html

javascript - 模仿黑色的谷歌菜单

html - 为什么 ionic 标签没有正确呈现?

firebase - ( ionic 4)当应用程序处于前台时无法使用 firebaseX 接收通知

javascript - Travis CI 是否支持 PhoneGap 应用程序?

html - 一旦 HTML 文档具有 list (cache.manifest),您如何删除它?

javascript - 作为选项卡 Pane 控件的单选按钮

html - 垂直文本不居中