CSS将超出容器宽度的文本自动替换为省略号

可使用text-overflow属性。效果如下图所示

<template>
    <section>
        <p id="clip">clip在内容区域上午极限处截断</p>
        <p id="ellipsis">ellipsis在内容区域的极限处将内容替换成省略号</p>
        <p id="str">字符串在内容区域的极限处将内容替换成省略号</p>
    </section>
</template>

<style lang="scss" scoped>
    #clip {
        width:100px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: clip
    }
    #ellipsis {
        width:100px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis
    }
    #str {
        width:100px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: "!!!"
    }
</style>

第三种用指定字符串代替多余部分兼容性差,试了试在火狐上可以正常显示,在Chrome上无法正常显示,只显示被截断。

posted @ 2018-12-10 10:15  番茄芥末饼  阅读(452)  评论(0编辑  收藏  举报