简体   繁体   English

如何在 Material UI 中制作高度响应文本字段?

[英]how to make a height responsive textfield in Material UI?

I need to make a textfield with a responsive height so the height will always adjust itself to the size of the parent grid when the browser is minimized/maximized.我需要制作一个具有响应高度的文本字段,因此当浏览器最小化/最大化时,高度将始终调整为父网格的大小。

I looked up for a solution and I only found this: Responsive MaterialUI TextField?我查找了一个解决方案,我只发现了这个: Responsive MaterialUI TextField?

and it only gave me an idea about how to solve the same problem that I had with the width.它只给了我一个关于如何解决与宽度相同的问题的想法。 it didn't work with the height.它不适用于高度。

here is my code:这是我的代码:

const useStyles = makeStyles({
infogrid: {
    width: '30%',
    height: '39%',
    display: 'inline-block',
    position: 'absolute',
    right: '8%',
    top: '10%',
    backgroundColor: '#00ffff',
    borderRadius: '5vh',
    alignItems: 'center',
    justifyContent: 'center',
    justifyItems: 'center',
    flexDirection: 'column',
    overflow: 'auto'
  },

label: {
    margin: '25%',
    marginTop: '0.3%',
    marginBottom: '0.3%',
    display: 'block',
    height: '9%',
    width: '50%',
    
  }
})


export default function App() {

  const  classes = useStyles()
  
  <Grid className={classes.infogrid}>
     
      <TextField fullWidth className={classes.label} id="ovalID" label="1" variant="outlined" />
      <TextField fullWidth className={classes.label} id="latitude" label="2" variant="outlined" />
      <TextField fullWidth className={classes.label} id="longitude" label="3" variant="outlined" />
      <TextField fullWidth className={classes.label} id="ovalRadius1" label="4" variant="outlined" />
      <TextField fullWidth className={classes.label} id="ovalRadius2" label="5" variant="outlined" />
      <TextField fullWidth className={classes.label} id="angel" label="6" variant="outlined" />

     
      </Grid>
 );  
}

Just wrap everything inside your <Grid> with a <Stack> component.只需使用<Stack>组件将所有内容包装在<Grid>中。

Example例子

<Grid>
  <Stack>
    <TextField />
    <TextField />
    <TextField />
    <TextField />
  </Stack>
</Grid>

Should make your TextField height responsive in the grid items.应该使您的TextField高度在网格项目中响应。

I just solved it by changing the parent grid into a div and changing the display setting of the div to 'flex'.我只是通过将父网格更改为 div 并将 div 的显示设置更改为“flex”来解决它。 Also, I set the marginTop and marginBottom settings in the 'labels' class to be a little bit higher.此外,我将“标签”class 中的 marginTop 和 marginBottom 设置设置得更高一点。

As long as the parent div have the flex direction set to 'column'.只要父 div 将 flex 方向设置为“列”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM