css - 无法更改 Material ui中文本字段的字体大小

标签 css reactjs material-ui

我正在努力学习 material ui。我想放大页面上的文本字段。但是,我在字段中嵌入的样式会更改高度、宽度和除大小之外的其他属性。以下是我的代码:

const styles = {
container: {
    display: 'flex',
    flexWrap: 'wrap',
},
textField: {
    // marginLeft: theme.spacing.unit,
    // marginRight: theme.spacing.unit,
    width: 300,
    margin: 100,
    fontSize: 50 //??? Doesnt work
}
}

无状态组件(React)如下:

const Searchbox = (props) => {

    const { classes } = props;

    return (
        <TextField
            onKeyDown={props.onKeyDown}
            id="with-placeholder"
            label="Add id"
            placeholder="id"
            className={classes.textField}
            margin="normal"
            autoFocus={true}
            helperText={"Add an existing id or select "}
        />
    );
};

export default withStyles(styles)(Searchbox);

我完全理解没有火箭科学,因为它是一种在 JS 中应用样式的简单 CSS 方法。

但是,我无法覆盖我的文本字段的基本字体大小。任何帮助将不胜感激

最佳答案

页面中提到TextField API将样式应用于将样式应用于输入元素的 InputProps

代码如下:

const styles = {
  container: {
    display: 'flex',
    flexWrap: 'wrap',
  },
  textField: {
    width: 300,
    margin: 100,
  },
  //style for font size
  resize:{
    fontSize:50
  },
}
<TextField
  id="with-placeholder"
  label="Add id"
  placeholder="id"
  InputProps={{
    classes: {
      input: classes.resize,
    },
  }}
  className={classes.textField}
  margin="normal"
  autoFocus={true}
  helperText={"Add an existing id or select "} />

关于css - 无法更改 Material ui中文本字段的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50319847/

相关文章:

javascript - 如何告诉 npm 在安装时使用父项目的依赖项构建模块?

reactjs - 我如何通过类原型(prototype)或 enzyme 包装器实例正确地监视 react 组件的方法?

html - Chrome 使用自定义样式为文本输入添加了意想不到的填充

javascript - 不使 div 可点击的 anchor 标记

javascript - React-router 在导航栏中添加链接

javascript - react + Spring 启动: Can't get Authorization value from Header

javascript - 如何从选择中获取两个不同的值?

css - jQuery 移动按钮拉伸(stretch)太远

php - 菜单元素事件状态

reactjs - 如何设置等同于 fetch 的 { credentials : "include" } in Redux Toolkit's createApi?