css - 如何更改 Material-UI TextField InputAdornment 背景颜色?

标签 css reactjs material-ui textfield

首先 10% 一种背景颜色,另外 90% 是另一种背景颜色。

<TextField
  className={classes.root}                  
  type="text"
  placeholder="username"
  variant="outlined"
  style={{borderRadius:'50',
    backgroundColor: "white"
  }}
  InputProps={{
    startAdornment: (
      <InputAdornment position="start">
        <PersonIcon />
      </InputAdornment>
    )
  }}
/>
我在下面附上演示文本字段
enter image description here

最佳答案

这就是你如何覆盖 InputAdornment在您的屏幕截图中实现相同的效果。请注意 input旁边InputAdornment有它的 box-sizing设置为 content-box ,所以不是设置height那么简单至 100%在装饰中。我不得不复制填充代码 here确保装饰物的高度与OutlinedInput的高度相同:

<TextField
  placeholder="With normal TextField"
  sx={{
    "& .MuiOutlinedInput-root": {
      paddingLeft: 0
    }
  }}
  InputProps={{
    startAdornment: (
      <InputAdornment
        sx={{
          padding: "27.5px 14px",
          backgroundColor: (theme) => theme.palette.divider,
          borderTopLeftRadius: (theme) =>
            theme.shape.borderRadius + "px",
          borderBottomLeftRadius: (theme) =>
            theme.shape.borderRadius + "px"
        }}
        position="start"
      >
        kg
      </InputAdornment>
    )
  }}
现场演示
V5
Codesandbox Demo
V4
Codesandbox Demo

关于css - 如何更改 Material-UI TextField InputAdornment 背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69554151/

相关文章:

html - 如何在输入框内显示封面图像使输入字段透明?

html - 如果对象在前面,React 三纤维 Html 标签不尊重

reactjs - 如何在 React 组件上设置组件默认 props

height - 当内容扩展超过窗口大小时,在绝对定位元素上设置 100% 高度

HTML CSS响应浏览器大小的变化位置

javascript - 浏览器中未定义的 React 组件 - ES6 导入/导出

javascript - 突出显示 MUI 数据表中的行

reactjs - 如何更改 MaterialUI 的 React Tabs 组件的下划线颜色?

javascript - 一个简单的问题: Material-UI TextField,如何在不同的断点处设置不同的字体大小?

css - 如何更改Grails的打印布局