gpt4 book ai didi

reactjs - 使用 Material-UI 纸垂直对齐

转载 作者:行者123 更新时间:2023-12-03 15:02:29 24 4
gpt4 key购买 nike

我想在 Material-UI Paper 组件中垂直对齐一些文本。

代码在这里:https://codesandbox.io/embed/material-demo-fz9wj

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';

const useStyles = makeStyles(theme => ({
root: {
padding: theme.spacing(3, 2),
height: 200,
verticalAlign: 'middle'
},
}));

function PaperSheet() {
const classes = useStyles();

return (
<div>
<Paper className={classes.root}>
<Typography variant="h5" component="h3">
This is a sheet of paper.
</Typography>
<Typography component="p">
Paper can be used to build surface or other elements for your application.
</Typography>
</Paper>
</div>
);
}

export default PaperSheet;

最佳答案

vertical-align CSS 属性仅适用于 display: block元素。

您可以选择声明您的 root使用 flexbox 的类:

const useStyles = makeStyles(theme => ({
root: {
padding: theme.spacing(3, 2),
height: 200,
display: "flex",
flexDirection: "column",
justifyContent: "center"
},
}));

关于reactjs - 使用 Material-UI 纸垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56342496/

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