我遇到了使用material-ui grid的问题,我想要渲染一行并拥有两列。
import React from 'react';
import DefaultLayout from '../layouts/default';
import Grid from '@material-ui/core/Grid';
class profile extends React.Component {
render() {
return (
<React.Fragment>
<Grid container spacing={8}>
<Grid item xs={12} style={{backgroundColor: 'blue', height: '250px'}}></Grid>
<Grid item xs={12} style={{backgroundColor: 'grey', height: '250px'}}></Grid>
{/* Form two columns with next row*/}
<Grid container={'true'} item sx={12}>
<Grid item={'true'} xs={6} md={8} style={{backgroundColor: 'green', height: '50px'}}></Grid>
<Grid item={'true'} xs={6} md={4} style={{backgroundColor: 'orange', height: '50px'}}></Grid>
</Grid>
</Grid>
</React.Fragment>
)}}
module.exports = profile;
目前,它正在渲染:
我希望橙色和绿色行成为同一行上的两列。并排显示。
有人能解释一下我的代码有什么问题吗?
@material-ui/core: ^3.9.2
react: ^16.7.0
<Grid item={'true'}>
,只需使用<Grid item>
即可。 - Jesse Novotny