Reactjs 如何在react material ui CardMedia组件中包含图像
某些图像要大得多,而且部分图像是隐藏的: 我能做的最接近正确的一件事是通过调整宽度和高度:Reactjs 如何在react material ui CardMedia组件中包含图像,reactjs,material-ui,contains,Reactjs,Material Ui,Contains,某些图像要大得多,而且部分图像是隐藏的: 我能做的最接近正确的一件事是通过调整宽度和高度: const useStyles = makeStyles((theme) => ({ ... media: { height: 100, width: 100, margin: 'auto', }, ... })); const Brands = (props) => { ... retur
const useStyles = makeStyles((theme) => ({
...
media: {
height: 100,
width: 100,
margin: 'auto',
},
...
}));
const Brands = (props) => {
...
return <div style={{ marginTop: props._marginTop }}>
<Grid container justify='center'>
<Grid item xs={10}>
<Grid container spacing={2}>
{brands.map((brand, i)=> {
return <Grid item key={i} lg={3} xs={12}>
<Card>
<CardMedia
className={classes.media}
image={brand.image.length > 0 ? brand.image : knightdemon}
title={brand.name}
/>
<CardContent>
<Typography gutterBottom variant="h5" component="h2">
{brand.name.toUpperCase()}
</Typography>
<Typography
onClick={()=>setFlip(true)}
className={classes.description}
gutterBottom variant="body2"
component="p"
>
DESCRIPTION
</Typography>
</CardContent>
</Card>
</Grid>
})}
</Grid>
</Grid>
</Grid>
</div>
}
export default Brands;
const useStyles=makeStyles((主题)=>({
...
媒体:{
身高:100,
宽度:100,
页边空白:“自动”,
},
...
}));
康斯特品牌=(道具)=>{
...
返回
{brands.map((brand,i)=>{
返回
0?brand.image:knightdemon}
title={brand.name}
/>
{brand.name.toUpperCase()}
setFlip(真)}
className={classes.description}
檐槽底部变型=“车身2”
component=“p”
>
描述
})}
}
出口默认品牌;
高度看起来都很好,问题是宽度,如果我增加它也会影响高度。
我如何在给定的空间中包含它们,使它们看起来像这样:
要在
CardMedia
中安装图像,请添加道具component=“img”
如下:
<CardMedia
className={classes.media}
image={brand.image.length > 0 ? brand.image : knightdemon}
title={brand.name}
component="img"
/>
0?brand.image:knightdemon}
title={brand.name}
component=“img”
/>
这应该可以解决您的问题。要使图像适合
CardMedia
,请添加道具component=“img”
:
<CardMedia
className={classes.media}
image={brand.image.length > 0 ? brand.image : knightdemon}
title={brand.name}
component="img"
/>
0?brand.image:knightdemon}
title={brand.name}
component=“img”
/>
这应该能解决你的问题。这很神奇,非常感谢@Giovanni。在媒体课上,我还必须去掉身高,但确实做到了。@LukasLukeStateczny很高兴听到这个消息。Ciao Ciao=)这就像魔术一样,非常感谢@Giovanni。在媒体课上,我还必须去掉身高,但确实做到了。@LukasLukeStateczny很高兴听到这个消息。Ciao Ciao=)