简体   繁体   English

如何更改材质 ui TextField 的 label 大小?

[英]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);

编辑TextField标签

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.

相关问题 如何更改材质 ui TextField 的 label 标高? - How can I change the label elevation of a material ui TextField? 如何在反应中更改 material-ui 文本字段标签样式 - How to change material-ui Textfield label styles in react 在Material-UI TextField中,当输入模糊时,如何防止标签落在装饰物后面? - In a Material-UI TextField how can I prevent a label from falling behind an adornment when the input is blurred? ReactJS:如何在 Material UI 中更改步进器标签的字体大小和 marginTop? - ReactJS: How to change font size and marginTop of stepper label in Material UI? 更改标签素材的字体大小 - Change the font size of a label material-ui Material UI:如何在 React Material Ui Stepper 中更改标签的字体大小? - Material UI: How to change font size of label in React Material Ui Stepper? 如何在 Material Ui 的 TextField 中更改日历的主题 - How to change theme of calendar in TextField in Material Ui 如何在错误和焦点上更改 Material-UI TextField 底部和标签颜色 - How to change Material-UI TextField bottom and label color on error and on focus 如何根据 TextField 的值以编程方式更新 Material UI TextField 的 helperText? - How can I programmatically update the helperText of a Material UI TextField based on the value of the TextField? 如何更改滑块(材质 ui)中标签的值? - how to change the value of label in slider (material ui)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM