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>

猜你喜欢

转载自www.cnblogs.com/tomatoto/p/10094998.html