我希望在使用material ui TextField时,TextField是裸体的(没有下划线).我知道从material ui使用InputBase可以实现这一点,但我需要使用TextField API来实现这一点,但我在API指南中没有找到实现这一点的方法.
我希望在使用material ui TextField时,TextField是裸体的(没有下划线).我知道从material ui使用InputBase可以实现这一点,但我需要使用TextField API来实现这一点,但我在API指南中没有找到实现这一点的方法.
尽管这是目前公认的答案,但请看other answer(使用disableUnderline
props ).我最近写了一个关于如何自定义下划线的答案(它使用了类似于这个答案的方法)之后,我写了这个答案,但没有注意到有一个专门用于删除下划线的属性.
下面是如何删除下划线的示例.:before
用于默认和悬停样式,:after
用于聚焦样式,因此这两种情况下都需要删除边框.
多个符号(如"&&&:before"
)增加规则的CSS specificity,使其胜过默认样式(如&:hover:not($disabled):before
).
import React from "react";
import ReactDOM from "react-dom";
import TextField from "@material-ui/core/TextField";
import { makeStyles } from "@material-ui/core/styles";
const useStyles = makeStyles({
underline: {
"&&&:before": {
borderBottom: "none"
},
"&&:after": {
borderBottom: "none"
}
}
});
function App() {
const classes = useStyles();
return <TextField defaultValue="default text" InputProps={{ classes }} />;
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
相关答案:How do I custom style the underline of Material-UI without using theme?