【发布时间】:2022-02-09 13:38:56
【问题描述】:
我正在尝试制作一个具有标题、内容和两个按钮的移动响应式服务条款页面。要求是:
- 组件不得超过视口的 100%,以便内容可滚动
- 按钮很粘(底部)
- 如果内容很短,则必须在标题下方,而不是在中间
- 该页面首先适合移动设备(横向和纵向)
我已经完成了大部分。使用设备工具栏,我可以在移动设备(横向和纵向)中查看它。问题是,如果切换到横向,组件会超过 100% 的高度。我尝试使用flexGrow,但它似乎不起作用,所以我现在的解决方法是指定不理想的高度以使其响应。
参考:div with 3 rows and scrollable content at the middle
这是一个独立的示例:https://stackblitz.com/edit/react-em99kh?file=src/App.js
App.js
const App = () => {
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
height: '100vh',
}}
>
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
<Box
sx={{
display: 'flex',
alignItems: 'center',
alignContent: 'center',
mb: 3,
mt: 3,
}}
>
<Typography variant="h3">{'Terms of Service'}</Typography>
</Box>
<Box
sx={{
display: 'flex',
overflow: 'scroll',
//Don't want to specify height
height: '70vh',
//flexgrow does nothing even if height is removed
flexGrow: 1,
}}
>
<Typography variant="body1">{data()}</Typography>
</Box>
</Box>
<Box
sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
mb: 3,
mt: 3,
}}
>
<Button
id="decline-btn"
color="primary"
variant="outlined"
sx={{
borderRadius: 16,
width: '47%',
height: '50px',
}}
>
{'Decline'}
</Button>
<Button
id="accept-btn"
color="primary"
variant="contained"
sx={{
borderRadius: 16,
width: '47%',
height: '50px',
}}
>
{'Accept'}
</Button>
</Box>
</Box>
);
};
export default App;
【问题讨论】:
标签: html css reactjs material-ui