MaterialUI如何将文本对齐到右侧或中心?

时间:2018-06-16 07:31:23

标签: css reactjs material-ui

如何对齐Material UI输入文本的文本?以下似乎不起作用。我正在使用版本1.x

import {Input} from 'material-ui';

//didn't work
<Input
   className="max-w-128 inline-block"
   style = {{textAlign: 'center'}}
   id="input-quantity"
   inputStyle={{ textAlign: 'center' }}
   //tried hintStyle as suggested in a bug
   hintStyle={{ width: '600px', textAlign: 'center' }}
   value={this.state.currentRecord.quantity}
   onChange={this.handleCurrentRecordTextChange('quantity')}
/>

2 个答案:

答案 0 :(得分:2)

你只需要使用(使用样式覆盖):

classes={{
 input: classes.inputCenter
}}

并且样式应该是:

const styles = theme => ({
  inputCenter: {
    textAlign: "center",
    color: "red"
  }
});

查看此处的文档:https://material-ui.com/api/input/#css-api

这是一个工作示例:https://codesandbox.io/s/n9nr9x8xo0

希望这会对你有所帮助。

答案 1 :(得分:0)

请使用 如果您已设置特定字体,请使用带有withStyle HOC的上述解决方案

相关问题