首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >反应-材料标签在Textfield中的位置不对

反应-材料标签在Textfield中的位置不对
EN

Stack Overflow用户
提问于 2021-09-17 03:27:38
回答 1查看 392关注 0票数 4

我试着在Codesandbox中使用相同的代码创建MUI文本字段,但是一切都很好。

我试着跟踪this post,但没有工作

有人能给我一些关于如何解决这个问题的想法吗?

代码语言:javascript
运行
复制
const textfieldUseStyles = makeStyles((theme) => ({
  root: {
    "& > *": {
      margin: "auto",
      width: "100%",
    },
  },
}));
...
const textFieldClasses = textfieldUseStyles();
return (
              <form className={textFieldClasses.root}>
                <TextField
                  key="Confirmation Code"
                  variant="outlined"
                  id="email"
                  label="Post title"
                  name="email"
                  autoComplete="confirmation code"
                  value="123"
                  InputLabelProps={{ shrink: true }}
                />
              </form>
)

更新1

在我在下面添加了css类之后,它变成了更好的UI。

代码语言:javascript
运行
复制
.MuiInputLabel-outlined.MuiInputLabel-shrink {
  transform: translate(0, -6px);
  font-size: 12px;
  margin: 0 14px;
  background-color: white;
}

我想要的是这样的东西,至少标签的位置是对的:

EN

回答 1

Stack Overflow用户

发布于 2022-05-25 20:59:45

梅v5中反对makeStyle!

您可以通过各种方式更改textFiled边框和其他属性,如:

  1. ,sx道具:

代码语言:javascript
运行
复制
     <TextField
          sx={{ '& .MuiOutlinedInput-root': { borderRadius: '20px' } }} // change border form here
          key="Confirmation Code"
          variant="outlined"
          id="email"
          label="Post title"
          name="email"
          autoComplete="confirmation code"
          value="123"
          InputLabelProps={{ shrink: true }}
        />

梅艳芳(

  1. Mui )造型组合方式(使用情感)

代码语言:javascript
运行
复制
import { styled } from '@mui/material/styles'
import TextField from '@mui/material/TextField'

export const StyledTextField = styled(TextField)(() => ({
  '& .MuiInputBase-root': {
    borderRadius: 20
  }
}))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69217419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档