Dav*_*vid 23

更新使用sx

<Typography
   sx={{
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      display: '-webkit-box',
      WebkitLineClamp: '2',
      WebkitBoxOrient: 'vertical',
   }}
>
</Typography>
Run Code Online (Sandbox Code Playgroud)


ber*_*ida 5

您可以使用makeStyles函数来创建multiLineEllipsis样式。

import { makeStyles } from "@material-ui/core/styles";

const LINES_TO_SHOW = 2;

// src: https://stackoverflow.com/a/13924997/8062659
const useStyles = makeStyles({
  multiLineEllipsis: {
    overflow: "hidden",
    textOverflow: "ellipsis",
    display: "-webkit-box",
    "-webkit-line-clamp": LINES_TO_SHOW,
    "-webkit-box-orient": "vertical"
  }
});
Run Code Online (Sandbox Code Playgroud)

然后你像下面一样使用这种风格

function App() {
  const classes = useStyles();

  return (
    <Typography className={classes.multiLineEllipsis}>
      Very long text here.
    </Typography>
  );
}
Run Code Online (Sandbox Code Playgroud)

编辑实用-微服务-0mexz