【发布时间】:2020-07-05 00:51:26
【问题描述】:
当我在一个项目中使用 Material UI 网格系统时,我正在使用 create-react-app。我有两个彼此相邻的网格项目。看起来像这样:
这正是我想要的。由于某些原因;但是,当页面加载一瞬间,右侧的文本会被向上推并闪烁,如下所示: 我怀疑这是因为图像尚未完全加载,因此文本位于较高位置,直到图像加载。任何有关如何防止这种情况的建议或建议将不胜感激!
这里是一个代码沙箱,用于重新创建https://codesandbox.io/s/nifty-jang-kbbty?file=/src/pages/Home.js
如果你在代码沙箱全屏时从主页转到/portfolio,你会看到我所说的无样式内容的闪烁。
<Grid container justify='center' alignItems='center'>
<Grid item xs={12} sm={9} md={9} lg={6} xl={6}>
<img src={JobTracker} alt='jobtracker' style={{ width: '100%' }} />
</Grid>
<Grid item xs={12} sm={9} md={9} lg={6} xl={6}>
<Container maxWidth='xs'>
<Typography variant='h3' style={{ textAlign: 'center' }}>
JobTracker
</Typography>
<br />
<Typography variant='body2'>
A platform that allows recent graduates from Wyncode Academy to
track job applications. Technologies used: ReactJS, NodeJS, Google
Cloud Functions, and Google Firestore.
</Typography>
</Container>
</Grid>
</Grid>
【问题讨论】:
-
I suspect it is because the image hasn't fully loaded是的。发现。要修复它,您需要知道图像的大小并更改您的 css 以适应它。 -
我是否需要创建一系列媒体查询来为每个屏幕尺寸布局我的图像尺寸?
-
老实说我没有这方面的专业知识,有人会插话的。但我会问 - 如果只有几毫秒,这有关系吗? - 编辑:为简洁起见,将图像调整为特定分辨率是一种常见操作,然后您可以将那些较低分辨率的图像输入不良连接并在以后缓冲更好的连接。不过这不是我的区域。
标签: css reactjs material-ui