admin管理员组文章数量:1432602
When I have a full width children in a Grid item, the children overlaps to the right side of its parent.
I have reproduced the code with the problem I'm having.
import React, { Component } from "react";
import { Paper, Grid, Button } from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";
class Demo extends Component {
render() {
const { classes } = this.props;
return (
<Paper>
<Grid container spacing={16}>
<Grid item xs={6}>
<Button variant="raised" fullWidth className={classes.button}>
asdf
</Button>
</Grid>
<Grid item xs={6}>
<Button variant="raised" fullWidth className={classes.button}>
asdf
</Button>
</Grid>
</Grid>
</Paper>
);
}
}
const styles = theme => ({
button: {
margin: theme.spacing.unit
}
});
export default withStyles(styles)(Demo);
When I have a full width children in a Grid item, the children overlaps to the right side of its parent.
I have reproduced the code with the problem I'm having. https://codesandbox.io/s/rn88r5jmn
import React, { Component } from "react";
import { Paper, Grid, Button } from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";
class Demo extends Component {
render() {
const { classes } = this.props;
return (
<Paper>
<Grid container spacing={16}>
<Grid item xs={6}>
<Button variant="raised" fullWidth className={classes.button}>
asdf
</Button>
</Grid>
<Grid item xs={6}>
<Button variant="raised" fullWidth className={classes.button}>
asdf
</Button>
</Grid>
</Grid>
</Paper>
);
}
}
const styles = theme => ({
button: {
margin: theme.spacing.unit
}
});
export default withStyles(styles)(Demo);
Gives me the result below:
Share Improve this question edited Oct 10, 2018 at 10:13 Ramil Amparo asked Oct 10, 2018 at 9:04 Ramil AmparoRamil Amparo 6322 gold badges10 silver badges25 bronze badges1 Answer
Reset to default 2The problem isn't the fullWidth prop, but the margin you are setting to the buttons, you can do something like this instead:
https://codesandbox.io/s/nnxl20l2q0
import React, { Component } from "react";
import { Paper, Grid, Button } from "@material-ui/core";
import { withStyles } from "@material-ui/core/styles";
class Demo extends Component {
render() {
const { classes } = this.props;
return (
<Paper className={classes.paper}>
<Grid container spacing={16}>
<Grid item xs={6}>
<Button variant="raised" fullWidth>
asdf
</Button>
</Grid>
<Grid item xs={6}>
<Button variant="raised" fullWidth>
asdf
</Button>
</Grid>
</Grid>
</Paper>
);
}
}
const styles = theme => ({
paper: {
padding: theme.spacing.unit
}
});
export default withStyles(styles)(Demo);
版权声明:本文标题:javascript - material-ui <Grid item> component's children with 100% width overlaps parent - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745606624a2665873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论