【发布时间】:2019-08-28 08:07:18
【问题描述】:
我从 React Material-UI 开始,如果高度较低,纸张组件不会使文本居中。有人可以帮忙吗?
下面有一个沙盒的链接,可以看到文字太靠下,不在中间。
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
const styles = theme => ({
root: {
...theme.mixins.gutters(),
height: '8px',
backgroundColor: 'pink',
paddingTop: theme.spacing.unit * 2,
paddingBottom: theme.spacing.unit * 2,
},
});
function PaperSheet(props) {
const { classes } = props;
return (
<div>
<Paper className={classes.root} elevation={1}>
ABC
</Paper>
</div>
);
}
PaperSheet.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(PaperSheet);
您可以在此处查看沙盒中的代码: https://codesandbox.io/s/o9k0392mj5?fontsize=14
【问题讨论】:
-
您将高度设置为小于文本高度。你想达到什么目的?如果只是去掉高度,高度会自动为文字高度加上内边距的高度。
-
但我希望它更短 - 并且文本非常适合 - 没有办法让它居中吗?
标签: reactjs material-ui