gpt4 book ai didi

reactjs - 如何在 Material UI 网格中添加水平滚动

转载 作者:行者123 更新时间:2023-12-04 13:41:57 25 4
gpt4 key购买 nike

我正在尝试使用网格布局构建看板。看板中有七列。我已经为每列使用了 materail Ui 网格。

我试过下面的 css 但它不起作用
overflow: auto;
width:100%

我也尝试过使用单列网格列表,但它也不起作用。

import React from 'react';
import PropTypes from 'prop-types';
import App from "../components/App";
import Header from "../components/Header";
import { withStyles } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
import GridList from '@material-ui/core/GridList';
import Paper from '@material-ui/core/Paper';
import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';

const styles = theme => ({
root: {
flexGrow: 1,
marginTop: 30,
display: 'flex',
oveflow: "auto",
maxWidth: "100%"
},
card: {
minWidth: 180,
marginBottom:20
},
bullet: {
display: 'inline-block',
margin: '0 2px',
transform: 'scale(0.8)',
},
title: {
fontSize: 14,
},
pos: {
marginBottom: 12,
},
content: {
flexGrow: 1
},
paper: {
maxWidth: 800,
margin: `${theme.spacing.unit}px auto`,
padding: theme.spacing(2)
},
});

function SimpleCard(props) {
const { classes } = props;
const bull = <span className={classes.bullet}>•</span>;

return (
<App>
<Header />
<main className={classes.content}>
<div className={classes.toolbar} />
<div className={classes.paper}>

<Grid container className={classes.root} spacing={16}>
<Grid item xs={2}>
<Paper className={classes.paper}>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="h2">
Task 1
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="h2">
Task 1
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="h2">
Task 1
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="h2">
Task 1
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
</Paper>

</Grid>
<Grid item xs={2}>
<Paper className={classes.paper}>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="h2">
Task 1
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
</Paper>
</Grid>
<Grid item xs={2}>
<Paper className={classes.paper}>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" component="h2">
Task 1
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
</Paper>
</Grid>
<Grid item xs={2}>
<Paper className={classes.paper}>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day Testing
</Typography>
<Typography variant="h5" component="h2">
Task 10000
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
</Paper>
</Grid>
<Grid item xs={2}>
<Paper className={classes.paper}>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day Testing
</Typography>
<Typography variant="h5" component="h2">
Task 11562
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
</Paper>
</Grid>
</Grid>
</div>
</main>
</App>
);
}

SimpleCard.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles, { withTheme: true })(SimpleCard);

如何在网格列布局中添加水平滚动?

最佳答案

请注意,当您缩小浏览器窗口时,它会出现水平滚动条。仅当内容溢出浏览器窗口外时才会出现水平滚动球。尝试将根的宽度设置为比浏览器窗口的宽度更宽。例如 2000 像素。并删除宽度:“100%”

关于reactjs - 如何在 Material UI 网格中添加水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55843133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com