javascript - 样式化 Muitextfield 输入背景,隐藏标签
问题描述
我正在尝试从全局主题中设置 Textfield 的样式,但是,我无法设法仅为输入设置彩色背景(白色),而在标签在输入内部移动时不隐藏标签。
但是,我有这个: 我将白色背景设置为透明,以表明文本确实在它后面,但是,如果我将透明度设置为不透明,标签将完全隐藏在白色背景后面,如下所示:
这是我的主题:
export const testGlobal = createMuiTheme({
palette: {
common: {
black: "#000",
white: "rgba(255, 255, 255, 1)",
blue: {
light: "rgba(184, 244, 255, 1)",
default: "rgba(0, 219, 255, 1)",
dark: "rgba(0, 184, 213, 1)",
},
red: {
light: "#ff1744",
default: "#fd0031",
dark: "#e3002c",
},
orange: {
light: "#ffc046",
default: "#ff8f00",
dark: "#c56000",
},
grey: {
light: "rgba(99, 99, 99, 1)",
medium: "rgba(99, 99, 99, 1)",
paper: "rgba(65, 65, 65, 1)",
default: "rgba(99, 99, 99, 1)",
dark: "rgba(60, 60, 60, 1)",
},
},
},
});
testGlobal.root = {
borderColor: "rgba(85, 85, 85, 1)",
};
testGlobal.img = {
width: "79%",
};
testGlobal.palette = {
...testGlobal.palette,
vumeter: {
top: "#fd0031",
mid: "#ff8f00",
bottom: "rgba(0, 219, 255, 1)",
},
playlist: {
playing: "#ef5350",
},
background: {
light: "rgba(99, 99, 99, 1)",
medium: "rgba(99, 99, 99, 1)",
paper: "rgba(65, 65, 65, 1)",
default: "rgba(99, 99, 99, 1)",
dark: "rgba(60, 60, 60, 1)",
},
primary: {
light: "rgba(184, 244, 255, 1)",
main: "rgba(0, 219, 255, 1)",
dark: "rgba(0, 184, 213, 1)",
contrastText: "rgba(255, 255, 255, 1)",
},
text: {
primary: "rgba(255, 255, 255, 0.87)",
secondary: "rgba(255, 255, 255, 0.54)",
disabled: "rgba(255, 255, 255, 0.38)",
hint: "rgba(255, 255, 255, 0.38)",
},
};
testGlobal.overrides = {
MuiFormLabel: {
root: {
background: "black",
fontWeight: "bolder",
color: "grey",
"&.Mui-focused": { color: "grey" },
paddingLeft: theme.spacing(1),
},
},
MuiInput: {
root: {
fontWeight: "bolder",
background: "white", // the white background that keep hiding my label :(
padding: theme.spacing(1),
color: "black",
},
},
};
testGlobal.props = {
MuiInput: { disableUnderline: true },
};
我没有向文本字段组件添加其他样式
为什么背景会出现在标签之上?:(
解决方案
如果您可以在 JavaScript 操场网站(例如codesandbox.io )上共享一个工作代码链接会很有帮助,但这听起来可能是个z-index
问题。尝试添加诸如position: relative;z-index: 99;
标签之类的东西。z-index
控制页面上的重叠顺序,因此这应该可以工作。
推荐阅读
- ldap - ASP.NET 样板 - Ldap 身份验证问题
- r - R:如何使用 XLConnect 的 setCellFormula 函数编写非英语的 excel 公式?
- javascript - SVG`
` javascript 动画未按预期工作 - assembly - 程序集标签前缀
- c# - 用脚本语言实现简洁的 IF 条件
- android - 如何使用颤振框架获取手机号码?
- reactjs - 将服务器端渲染添加到现有的 React 应用程序
- android - Firebase 云消息传递如何在 Android 上运行
- eclipse - Eclipse 的嵌入式 Maven 不接受运行时参数
- sql - 使用游标内的游标进行更新,它显示受影响的行,当我手动尝试时逻辑正在工作