在 Material-UI 的组件中,您可以为组件本身提供一个样式对象作为 JSX 标签上的一个属性,但是您必须为 underlineFocusStyle 提供一个单独的样式对象。
我的意思是例如 TextField 组件的 underlineFocusStyle。
你会这样设计它:
<TextField hintText="Hint Text" style={{width: '80%'}}
underlineFocusStyle={{backgroundColor: '#0000FF', height: '2px'}}
/>
现在,如何在普通的 css 中编写它。组件的 underlineFocusStyle 样式在 TextField 组件样式本身的样式之上?
例如,TextField 的宽度样式当然是:
宽度:100%
但是如何设置 underlineFocusStyle 的样式呢? 像这样的东西:
width: 100&
.underline-focus-style: background-color: #000FF
因为我要给组件一个样式,必须用css写。谢谢。
最佳答案
您可以将 css 样式应用于 underlineFocusStyle 以及任何 material-ui 组件。声明一个 const 样式对象并添加你的 css,如下所示
const style = {
"background-color": "#fff", color:"#333"
}
然后将此样式对象传递给如下所示的 underlineFocusStyle Prop
<TextField underlineFocusStyle={style} />
希望这能回答您的问题。
关于css - 在普通 css 上设计 material-ui TextField 组件的 underlineFocusStyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48202290/