美文网首页
长文本溢出带省略号

长文本溢出带省略号

作者: 家有饿犬和聋猫 | 来源:发表于2020-04-07 14:22 被阅读0次

index.jsx

import React from 'react';
import { Tooltip } from 'antd';
import styles from './index.scss';

const Ellipsis = ({text, length}) => {
    if(text === 'null' || text === null){
        text = '--';
    }
    return (
        <Tooltip title={text} >
            <span className={styles.textEllipsis} style={{width: `${length || 150}px`}}>{text}</span>
        </Tooltip>
    );
};

export default Ellipsis;

scss

.textEllipsis {
    overflow: hidden;
    display: inline-block;
    white-space: nowrap;
    width: 150px;
    text-overflow: ellipsis;
}
:global{
    .ant-tooltip-placement-top{
        min-width: 230px;
    }
}

效果图


image.png
image.png

相关文章

网友评论

      本文标题:长文本溢出带省略号

      本文链接:https://www.haomeiwen.com/subject/gzxnphtx.html