reactjs - Change Grid item column order on small screens
问题描述
I'm attempting to have a grid looking like this for larger displays:
and this for smaller sizes:
Currently the skeleton of my grid is succinctly like this:
<Fragment>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<img src={img1} />
</Grid>
<Grid item xs={12} md={6}>
<Paper>Text Content 1...</Paper>
</Grid>
</Grid>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<Paper>Text Content 2...</Paper>
</Grid>
<Grid item xs={12} md={6}>
<img src={img2} />
</Grid>
</Grid>
</Fragment>
How can I do such as in mobile view (width 12) the first Grid item
from the second Grid container
(Text content 2) displays after (below) the image?
解决方案
Use like this:
<Grid container>
<Grid spacing={3} container item xs={12} md={12}>
<Grid item xs={12} md={6} className={classes.item}>
<img
width="50px"
src="https://cdn3.vectorstock.com/i/1000x1000/37/37/simple-cartoon-a-cute-bear-vector-18823737.jpg"
alt="abc"
/>
</Grid>
<Grid container item xs={12} md={6} className={classes.item}>
<Paper>Text Content 1...</Paper>
</Grid>
</Grid>
<Grid container item spacing={3} xs={12} md={12} className="flexgrid">
<Grid container item xs={12} md={6} className={classes.item}>
<Paper>Text Content 2...</Paper>
</Grid>
<Grid container item xs={12} md={6} className={classes.item}>
<img
width="50px"
src="https://cdn3.vectorstock.com/i/1000x1000/37/37/simple-cartoon-a-cute-bear-vector-18823737.jpg"
alt="abd"
/>
</Grid>
</Grid>
</Grid>
for re-order added:
<Grid container item spacing={3} xs={12} md={12} className="flexgrid">
and css :
@media screen and (max-width: 720px) {
.flexgrid{
flex-direction: column-reverse
}
}
推荐阅读
- sql - SQL 查询 - 将编码转换为 UTF-8
- c++ - 如何将预编译/预编译的 *.o 目标文件添加到 GN 中的可执行文件
- mysql - 如何从子查询中获取最大值?
- android - 如何准确检测所有 OnePlus 设备?
- javascript - Drag-gable 项目没有移动。如何解决?
- reactjs - ag-grid 行组正在重复
- python - 拆分数据框列并重命名收到的列类型错误
- python - 序列化没有文件系统的 Python 对象
- html - 我正在尝试使用 Django CMS 和模板。但在编辑模板时出错
- geo - ModuleNotFoundError:没有名为“geo”的模块