[英]How can I change the label size of a material ui TextField?
I have a TextField defined as follows:我有一个 TextField 定义如下:
<TextField
id="standard-with-placeholder"
label="First Name"
className={classes.textField}
margin="normal"
/>
And it looks like this:它看起来像这样:
But I want it look like this:但我希望它看起来像这样:
The "First Name" text is larger. “名字”文本较大。 How can I adjust the label text size?
如何调整 label 文字大小? Currently my styles object is empty.
目前我的 styles object 是空的。 I think that should be where the CSS to do this should go, but I'm unsure what the css would look like for the label text.
我认为应该是Z2C56C360580420D293172F42D85DFBBEDZ这样做的,应该做Z34D1F91FB2E514B8576FAB1A75A75A6A6BZ
Thanks谢谢
Here's an example of how to modify the label font size. 这是有关如何修改标签字体大小的示例。 This example also modifies the font-size of the input on the assumption that you would want those sizes to be in sync, but you can play around with this in the sandbox to see the effects of changing one or the other.
本示例还假设您希望输入的字体大小保持同步,但也可以修改它们的字体大小,但是您可以在沙盒中试用该字体大小,以查看更改一个或另一个的效果。
import React from "react";
import ReactDOM from "react-dom";
import TextField from "@material-ui/core/TextField";
import { withStyles } from "@material-ui/core/styles";
const styles = {
inputRoot: {
fontSize: 30
},
labelRoot: {
fontSize: 30,
color: "red",
"&$labelFocused": {
color: "purple"
}
},
labelFocused: {}
};
function App({ classes }) {
return (
<div className="App">
<TextField
id="standard-with-placeholder"
label="First Name"
InputProps={{ classes: { root: classes.inputRoot } }}
InputLabelProps={{
classes: {
root: classes.labelRoot,
focused: classes.labelFocused
}
}}
margin="normal"
/>
</div>
);
}
const StyledApp = withStyles(styles)(App);
const rootElement = document.getElementById("root");
ReactDOM.render(<StyledApp />, rootElement);
Here are the relevant parts of the documentation: 以下是文档的相关部分:
You can target the textfield label like this:您可以像这样定位文本字段 label:
.MuiFormLabel-root {
font-size: 20px !important;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.