简体   繁体   English

如何在反应中对齐按钮、文本字段和中心文本?

[英]how to align the butto, textfield and text in the center in react?

how to align the button, textfield and text in the center in react?如何在反应中对齐中心的按钮、文本字段和文本? 在此处输入图片说明

    <div className="row text-center">
      <div className="text-center col-12">
        <div className="form-group text-center col-4">
          <div style={{ fontSize: "18px" }} className="field-label mb-2">
            Apply Now
          </div>
          <input
            style={{ height: "38px" }}
            className="col-12 mb-2"
            type="email"
            name="email"
            placeholder="email"
            value={email}
            onChange={e => onEmailChange(e)}
          />
          {validator.message("email", email, "required|alpha")}
          <button
            className="btn-solid btn col-12"
            style={{ height: "45px" }}
            type="button"
            disabled={isEmailLoading}
            onClick={e => onClickApply(e)}>
            {isEmailLoading ? (
              <CircularProgress color="inherit" size={20} className="" />
            ) : (
              "Apply"
            )}
          </button>
        </div>
      </div>
    </div>

As i can see you're using class col-4 for your entire form.正如我所看到的,您在整个表单中都使用了col-4类。 If your grid system is 12-cols (I guess it is!) your columns will be placed from left!如果您的网格系统是 12 列(我猜是!),您的列将从左侧放置! Unless you assign offset to them(to ignore some col).除非您为它们分配偏移量(忽略某些列)。 If you want to put your col in center, you have to use offset!如果你想把你的 col 放在中心,你必须使用 offset! in this situation you need to pass 4 cols to center your items!在这种情况下,您需要传递 4 个列来使您的项目居中! If you're using bootstrap you can use offset-4 easily!如果您使用引导程序,则可以轻松使用offset-4

More detail about offset in grid systems like bootstrap: Offset Classes in Bootstrap有关网格系统中偏移的更多详细信息,例如 bootstrap: Bootstrap 中的偏移类

Your div class example:您的 div 类示例:

className="form-group text-center col-4 offset-4"

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

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