css - 如何更改 MUI 输入下划线颜色?

标签 css reactjs material-ui

我有一个深色背景上的 MUI Select 组件,因此我只想对这一个组件进行更改,以便文本和线条颜色均为白色。 Select 实例的其余部分应保持不变。

虽然我可以让文本和图标改变颜色,但我似乎无法弄清楚如何使用 classes 属性来设置下划线颜色。我的尝试似乎也使打开的图标也换行到下一行。这是一个演示问题的示例:

Edit Material demo

我的风格是这样的:

const styles = theme => ({
  underline: {
    borderBottom: '2px solid white',
    '&:after': {
      // The MUI source seems to use this but it doesn't work
      borderBottom: '2px solid white',
    },
  }
};

然后我这样设置:

<Select
  classes={{
    underline: classes.underline,     // Does it go here?
  }}
  inputProps={{
    classes: {
      underline: classes.underline,   // Or does it go here?
    },
  }}
>

此方法对文本有效(上面未显示,但在链接的示例中),它只是我无法更改的下划线颜色。我错过了什么?

最佳答案

您可以更改 Select 的下划线颜色使用两个选项的组件

<强>1。用类覆盖

创建一个 <Input />元素使用 input使用 underline 使用类的 Prop 和覆盖键。

<Select
            value={this.state.age}
            onChange={this.handleChange}
            input={<Input classes={{
              underline: classes.underline,
            }}
             name="age" id="age-helper" />}>

我在你的沙盒中应用了这个,看看这个 here

<强>2。使用 MuiThemeProvider

const theme = createMuiTheme({
  palette: {
    primary: green,
  },
});

并使用 <MuiThemeProvider/> 应用主题

我已经在这个沙盒中应用了这两个

Customising Select

关于css - 如何更改 MUI 输入下划线颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50620393/

相关文章:

css - 哪些字符在 CSS 类名/选择器中有效?

html - CSS(尤其是 CSS3)允许使用百分比宽度吗?

javascript - React 使用外部函数作为方法

javascript - 如何在 react 中使用另一个文件中的 Prop ?

javascript - 制作一个弹出窗口(这是一个包含面板的 DIV - 由文本框和一个按钮组成)以仅适合( float )在( map )特定的 DIV 中

html - 将原始 HTML 代码转换为 PDF 文件

css - React 应用程序 - 避免样式被其他 CSS 覆盖

javascript - React-Strap 的日期选择器

html - 尝试使用 npm 安装 mui core 时出错

javascript - 在 Material ui 中使用 useMediaQuery?