简体   繁体   English

如果使用 css 的 div 和 Reactjs 组件中没有空格,如何在显示少量文本后显示三个点

[英]How to show three dots after few text showing, if no space in div using css and in Reactjs component

how to show three dots if space excided the text in css. when increase we need to show the character without effecting sibliing compoenent.如果空格超出 css 中的文本,如何显示三个点。当增加时,我们需要在不影响兄弟组件的情况下显示字符。

在此处输入图像描述

I'm trying something below我正在尝试下面的东西

import React from 'react'
import Tooltip from '@material-ui/core/Tooltip'
import Typography from '@material-ui/core/Typography'
import { makeStyles, createStyles, withStyles } from '@material-ui/core/styles'
import { Divider } from '@material-ui/core'
import { Link, Paper } from '@material-ui/core'
import { ErrorOutlineOutlinedIcon } from '../../icon'


const HtmlTooltip = withStyles(theme => ({
    arrow: {
        '&::before': {
            color: 'white'
        }
    },
    tooltip: {
        backgroundColor: '#f5f5f9',
        boxShadow: theme.shadows[8],
        color: 'rgba(0, 0, 0, 0.87)',
        fontSize: 14,
        maxWidth: 800,
        padding: 0,
    },
    tooltipPlacementTop: {
        margin: '4px 0',
    },
}))(Tooltip)
const imageStyles = { root: { color: 'deeppink', height: 20, marginBottom: 0, width: 20 } }

const Image = withStyles(imageStyles)(({ classes }) => (
    <ErrorOutlineOutlinedIcon classes={classes} />
))
const useStyles = makeStyles(theme =>
    createStyles({
        content: {
            border: `1px solid ${theme.palette.grey[300]}`,
            margin: 0,
            minWidth: 600,
            padding: 0,
            zIndex: 1,
        },
        contentInner: {
            padding: theme.spacing(1)
        },
        header: {
            backgroundColor: 'deeppink',
            fontWeight: 'bold',
            padding: theme.spacing(1),
        }
    })
)
export default function CustomTooltip(params) {
    const classes = useStyles()
    const action = [ {
        content: '<pre>Check Delhi in India or not</pre>',
        name: 'Check Delhi in India or not',
        value: <pre>Check Delhi in India or not</pre>
    } ]
    const textDispaly = action.some(c => c.content === params.value) ? action.find(c => c.content === params.value).value : params.value
    const labelDisplay = action.some(c => c.content === params.value) ? action.find(c => c.content === params.value).name : params.value

    return (
        <>
            {labelDisplay && labelDisplay.length > 20 ? (<HtmlTooltip arrow interactive title={
                <Paper className={classes.content}>
                    <div className={classes.header}>
                        <Typography color='inherit' variant='body1' style={{color: 'white', fontSize: '16px'}}>
                            {params.column.colDef.headerName}
                        </Typography>
                    </div>
                    <Divider />
                    <div className={classes.contentInner}>
                        {textDispaly}
                    </div>
                </Paper>}
            placement='top'
            >
                <div style={{ alignItems: 'center', display: 'flex', fontSize: '14px', justifyContent: 'space-between' }}>
                    <div style={{textOverflow: 'ellipsis'}}>{labelDisplay}</div><Image/>
                </div>
            </HtmlTooltip>) : (<div style={{textOverflow: 'ellipsis'}}>{labelDisplay}</div>)}
        </>
    )
}

I have missed some properties and added later which are over-flow: hidden and white-space: 'nowrap'我错过了一些属性,后来添加了溢出的属性:隐藏空白:'nowrap'

<div style={{overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap'}}>{labelDisplay}</div>

Implemented Component实现组件

import React from 'react'
import Tooltip from '@material-ui/core/Tooltip'
import Typography from '@material-ui/core/Typography'
import { makeStyles, createStyles, withStyles } from '@material-ui/core/styles'
import { Divider } from '@material-ui/core'
import { Link, Paper } from '@material-ui/core'
import { ErrorOutlineOutlinedIcon } from '../../icon'


const HtmlTooltip = withStyles(theme => ({
    arrow: {
        '&::before': {
            color: 'white'
        }
    },
    tooltip: {
        backgroundColor: '#f5f5f9',
        boxShadow: theme.shadows[8],
        color: 'rgba(0, 0, 0, 0.87)',
        fontSize: 14,
        maxWidth: 800,
        padding: 0,
    },
    tooltipPlacementTop: {
        margin: '4px 0',
    },
}))(Tooltip)
const imageStyles = { root: { color: 'deeppink', height: 20, marginBottom: 0, width: 20 } }

const Image = withStyles(imageStyles)(({ classes }) => (
    <ErrorOutlineOutlinedIcon classes={classes} />
))
const useStyles = makeStyles(theme =>
    createStyles({
        content: {
            border: `1px solid ${theme.palette.grey[300]}`,
            margin: 0,
            minWidth: 600,
            padding: 0,
            zIndex: 1,
        },
        contentInner: {
            padding: theme.spacing(1)
        },
        header: {
            backgroundColor: 'deeppink',
            fontWeight: 'bold',
            padding: theme.spacing(1),
        }
    })
)
export default function CustomTooltip(params) {
    const classes = useStyles()
    const action = [ {
        content: '<pre>Check Delhi in India or not</pre>',
        name: 'Check Delhi in India or not',
        value: <pre>Check Delhi in India or not</pre>
    } ]
    const textDispaly = action.some(c => c.content === params.value) ? action.find(c => c.content === params.value).value : params.value
    const labelDisplay = action.some(c => c.content === params.value) ? action.find(c => c.content === params.value).name : params.value

    return (
        <>
            {labelDisplay && labelDisplay.length > 20 ? (<HtmlTooltip arrow interactive title={
                <Paper className={classes.content}>
                    <div className={classes.header}>
                        <Typography color='inherit' variant='body1' style={{color: 'white', fontSize: '16px'}}>
                            {params.column.colDef.headerName}
                        </Typography>
                    </div>
                    <Divider />
                    <div className={classes.contentInner}>
                        {textDispaly}
                    </div>
                </Paper>}
            placement='top'
            >
                <div style={{ alignItems: 'center', display: 'flex', fontSize: '14px', justifyContent: 'space-between' }}>
                    <div style={{overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap'}}>{labelDisplay}</div><Image/>
                </div>
            </HtmlTooltip>) : (<div style={{overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap'}}>{labelDisplay}</div>)}
        </>
    )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅当文本从 div 溢出时,如何在 reactjs 中使用纯 css javascript 显示更多内容 - How to display show more only when text overflows from a div using pure css javascript in reactjs 单击提交按钮几秒钟后如何显示div然后消失? - how to show div after clicking submit button for few seconds then disappear? 点击几秒钟后如何显示div - how to show div after click only for few seconds 截断文本以适合 3 行并在 Html 中显示三个点 - Truncate text to fit in 3 lines and show three dots in end In Html 如何让替代文字通过页面上图像的替代文字旋转,每隔几秒钟显示一个接一个??? 使用 jquery - How can make alt text rotates through the alt text of the images on the page showing one after another every few seconds??? using jquery 如何在几秒钟内更改 Reactjs 中的按钮文本? - How to change button text in Reactjs for a few seconds? 如何使用 reactjs 显示内容而不显示按钮? - How to show the content without showing button using reactjs? 几秒钟后如何使用jQuery mobile隐藏div? - how to hide a div after a few seconds using jQuery mobile? 如何使用CSS或Javascript隐藏和显示DIV - How To Hide and Show DIV using CSS or Javascript 如何使用 css 在子 div 底部显示文本? 我试过了,但文本转到主 div - How can I show the text at the bottom of a child div using css? I have tried, but the text goes to main div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM