Javascript 如何为材质UI卡创建角功能区?

Javascript 如何为材质UI卡创建角功能区?,javascript,css,reactjs,material-ui,Javascript,Css,Reactjs,Material Ui,如何将角功能区添加到材质UI卡?对于我使用的makeStyles来自Material UI的样式,您可以在材质UI卡上添加4个功能区,即(左上角、左右下角、左下角和右下角) 只需使用材质ui设计制作卡片即可 并设置卡相对于父容器的位置&makeinsidediv&将其位置设置为绝对 下面请参见代码u可以添加css伪元素以调整功能区边框 import React from 'react'; import { makeStyles } from '@material-ui/core/styles';

如何将角功能区添加到
材质UI
卡?对于我使用的
makeStyles
来自
Material UI
的样式,您可以在材质UI卡上添加4个功能区,即(左上角、左右下角、左下角和右下角)

  • 只需使用材质ui设计制作卡片即可

  • 并设置卡相对于父容器的位置&makeinsidediv&将其位置设置为绝对

  • 下面请参见代码u可以添加css伪元素以调整功能区边框

    import React from 'react';
    import { makeStyles } from '@material-ui/core/styles';
    import Card from '@material-ui/core/Card';
    import CardActionArea from '@material-ui/core/CardActionArea';
    import CardActions from '@material-ui/core/CardActions';
    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';
    
    root: {
        margin: '0 auto',
        width: 500,
    },
    card: {
        maxWidth: 360,
        marginTop: 40,
        position: "relative",
    },
    ribbon: {
        backgroundColor: 'skyblue',
        position: "absolute",
        color: 'white',
        width: 150,
        zIndex: 3,
        textAlign: 'center',
        textTransform: 'uppercase',
        padding: 5,
        font: 'Lato',
        '&::before': {
            position: "absolute",
            zIndex: -1,
            content: '',
            display: 'block',
            border: '5px solid #2980b9',
        },
        '&::after': {
            position: "absolute",
            zIndex: -1,
            content: '',
            display: 'block',
            border: '5px solid #2980b9',
        },
        transform: 'rotate(-45deg)',
        top: 60,
        marginLeft: -40,
    },
    span: {
    
    }
    
    export default function RibbonMaterialCard() {
      const classes = useStyles();
    
      return (
        <div className={classes.root}>
           <div className={classes.ribbon}><span className={classes.span}>ribbon</span> 
           </div>
        <Card className={classes.card}>
        <CardActionArea>
            <CardMedia
            component="img"
            alt="Contemplative Reptile"
            height="140"
            image="/static/images/cards/contemplative-reptile.jpg"
            title="Contemplative Reptile"
            />
            <CardContent>
            <Typography gutterBottom variant="h5" component="h2">
                Lizard
            </Typography>
            <Typography 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
            </Typography>
            </CardContent>
        </CardActionArea>
        <CardActions>
            <Button size="small" color="primary">
            Share
            </Button>
            <Button size="small" color="primary">
            Learn More
            </Button>
        </CardActions>
        </Card>
    </div>
    );
    }
    
    从“React”导入React;
    从'@material ui/core/styles'导入{makeStyles};
    从“@material ui/core/Card”导入卡片;
    从“@material ui/core/CardActionArea”导入CardActionArea;
    从“@material ui/core/CardActions”导入CardActions;
    从“@material ui/core/CardContent”导入CardContent;
    从“@material ui/core/CardMedia”导入CardMedia;
    从“@material ui/core/Button”导入按钮;
    从“@material ui/core/Typography”导入排版;
    根目录:{
    边距:“0自动”,
    宽度:500,
    },
    卡片:{
    最大宽度:360,
    玛金托普:40,
    职位:“相对”,
    },
    功能区:{
    背景颜色:“天蓝色”,
    位置:“绝对”,
    颜色:'白色',
    宽度:150,
    zIndex:3,
    textAlign:'中心',
    textTransform:'大写',
    填充:5,
    字体:“Lato”,
    “&::before”:{
    位置:“绝对”,
    zIndex:-1,
    内容:“”,
    显示:“块”,
    边框:“5px实心#2980b9”,
    },
    “&::在”:{
    位置:“绝对”,
    zIndex:-1,
    内容:“”,
    显示:“块”,
    边框:“5px实心#2980b9”,
    },
    变换:“旋转(-45度)”,
    排名:60,
    边缘左侧:-40,
    },
    跨度:{
    }
    导出默认函数RibbonMaterialCard(){
    const classes=useStyles();
    返回(
    带子
    蜥蜴
    蜥蜴是一种广泛分布的有鳞爬行动物,有6000多种
    种类,范围
    跨越除南极洲以外的所有大陆
    共有
    了解更多
    );
    }
    

  • 欢迎来到堆栈溢出!请通读一遍,尤其是你在这里的最佳选择是做你的研究,对于相关的话题等等,并尝试一下。如果你在做了更多的研究和搜索后陷入困境,无法摆脱困境,请发布一份你的尝试,并明确指出你陷入困境的地方。人们会乐意帮忙的。