Как применить цвет градиента в конце содержимого? [дубликат]

Aug 18 2020

Я пытаюсь воспроизвести добавленный ниже пользовательский интерфейс изображения (взято из раздела описания курса udemy.com ). Я искал способ создать подобный интерфейс градиента только для некоторых частей контента, как показано на изображении ниже.

Вот образец кода, в котором я экспериментировал https://codesandbox.io/s/fervent-einstein-doeql?file=/src/Demo.js. Я пытаюсь применить именно этот пользовательский интерфейс к material-uiсодержимому карты. Вот Demo.jsгде у меня определено содержимое карты

import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import CardMedia from "@material-ui/core/CardMedia";
import Button from "@material-ui/core/Button";
import Typography from "@material-ui/core/Typography";

const useStyles = makeStyles({
  root: {
    maxWidth: 345
  }
});

export default function ImgMediaCard() {
  const classes = useStyles();

  return (
    <Card className={classes.root}>
      <CardMedia
        component="img"
        alt="Contemplative Reptile"
        image="https://images.unsplash.com/photo-1503803548695-c2a7b4a5b875?ixlib=rb-1.2.1&w=1000&q=80"
        title="Contemplative Reptile"
      />
      <CardContent>
        <Typography gutterBottom variant="h5" component="h2">
          Lizard
        </Typography>
        <Typography
          className="content"
          variant="body2"
          color="textSecondary"
          component="p"
        >
          Lizards are a widespread group of squamate reptiles, with over 6,000
          species, ranging across all continents except Antarctica Lizards are a
          widespread group of squamate reptiles, with over 6,000 species,
          ranging across all continents except Antarctica Lizards are a
          widespread group of squamate reptiles, with over 6,000 species,
          ranging across all continents except Antarctica Lizards are a
          widespread group of squamate reptiles, with over 6,000 species,
          ranging across all continents except Antarctica Lizards are a
          widespread group of squamate reptiles, with over 6,000 species,
          ranging across all continents except Antarctica Lizards are a
          widespread group of squamate reptiles, with over 6,000 species,
          ranging across all continents except Antarctica Lizards are
        </Typography>
      </CardContent>
      <div className="button">
        <Button size="small">Read more</Button>
      </div>
    </Card>
  );
}

и мой styles.css

.content {
  max-height: 100px;
}

.content:hover {
  max-height: none;
}

.button {
  display: flex;
  margin-top: 5px;
  justify-content: flex-end;
  width: 100%;
  background-color: grey;
}

Любая помощь приветствуется. Спасибо 🙂

Ответы

Adam Aug 18 2020 at 18:00

Я не уверен, что понимаю вопрос. Если я перейду к песочнице с образцом кода, она действительно расширяется при наведении курсора. Может ты нашел ответ?