I have created a card in Material UI containing text. I'd like to fix the height of the card and have the text within it truncate if it goes beyond 3 lines. What's the best way to do this?
Below is my code where, as you can see, I have tried to use CSS to do this, but (a) the ellipses doesn't show (b) the overflow chops off the text on the horizontal so I'd like to have a way to do it by multiples of the line height rather than by pixels. I'd also like it to still work if the monitor size adjusts.
import React from 'react';
// Material UI
import {
Card,
CardActionArea,
CardContent,
CardMedia,
makeStyles,
Typography,
} from '@material-ui/core';
const useStyles = makeStyles(theme => ({
media: {
height: 140,
},
title: {
height: 50,
overflow: 'hidden',
textOverflow: 'ellipsis',
},
description: {
height: 50,
overflow: 'hidden',
textOverflow: 'ellipsis',
},
}));
const ContentThumbnail = ({ image, title, description, date }) => {
const classes = useStyles();
return (
<Card>
<CardActionArea>
<CardMedia
image={image}
title=""
className={classes.media}
/>
<CardContent>
<Typography gutterBottom variant="h5" component="h2" className={classes.title}>
{title}
</Typography>
<Typography variant="body2" component="p" className={classes.description}>
{description}
</Typography>
</CardContent>
</CardActionArea>
</Card>
);
};
export default ContentThumbnail;