html - 错误消息更改所有 block 的宽度。如何解决?

标签 html css material-ui

当出现错误消息时,它会更改登录表单的宽度。 短消息使它更短和更长。如何在不添加固定的情况下修复它?

我使用 FormHelperText 元素来显示错误消息。 在 FormControl 中移动 FormHelperText 并不能解决问题。

// some code ....
  render () {
    const { email, password, error } = this.state;
    const isInvalid = password === '' || email === '';

    return (
      <Paper className={styles.paper}>
        <Avatar className={styles.avatar}>
          <LockOutlinedIcon />
        </Avatar>
        <Typography component='h1' variant='h5'>
          Login
        </Typography>
        <form onSubmit={this.onSubmit} className={styles.form}>
          <FormControl margin='normal' required fullWidth>
            <InputLabel htmlFor='email'>Email Address</InputLabel>
            <Input
              id='email'
              name='email'
              autoComplete='off'
              autoFocus value={email}
              onChange={this.onChange}
            />
          </FormControl>
          <FormControl margin='normal' required fullWidth>
            <InputLabel htmlFor='password'>Password</InputLabel>
            <Input
              name='password'
              type='password'
              id='password'
              autoComplete='off'
              value={password}
              onChange={this.onChange}
            />
          </FormControl>
          {error &&
            <FormHelperText className={styles.error} error>{error.message}</FormHelperText>
          }
          <Button
            type='submit'
            fullWidth
            variant='contained'
            color='primary'
            disabled={isInvalid}
            className={styles.formSubmitBtn}
          >
            Login
          </Button>
        </form>
      </Paper>
    );
  }
.paper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar {
  margin-top: 20px;
}

.error {

}

.form {
  margin: 30px 30px;

  &__submit-btn {
    margin-top: 20px !important;
  }
}

short error message

default

最佳答案

您可以在 CSS 中指定 max-widthmin-width 属性。他们将确保宽度保持在指定尺寸之间。如果内容超过max-width,就会影响框的高度。

关于html - 错误消息更改所有 block 的宽度。如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55991653/

相关文章:

javascript - React Material onClick Collapse [答案已更新]

reactjs - 如何在 Material UI 中覆盖由 TabPanel 创建的 Box

html - 位置 : sticky not working in desktop but OK in mobile

html - 垂直对齐 :top not working on table when printing

python - scrapy中如何提取准确的标签

javascript - 如何获取视频海报的图像尺寸?

javascript - Bootstrap-wysihtml5 : content uneditable

javascript - 当元素存在时,“classList”属性返回 null?

css - 如何控制 material-ui SelectField 的样式

javascript - HTML 设置选择时的默认文本