首页 > 解决方案 > 如何将 ReactJS-bootstrap 表单和 h1 标签并排放置

问题描述

我想将我的 FormGroup 和我的 h1 标签水平并排放置。我试过使用 display: inline-block 和其他各种东西,但没有运气。这是我的 .css 代码:

.testingForm {
  max-width: 320px;
}

.testingMore {
  text-align: left;
  float: right;
}

这是 .js 代码:

<div className="testingForm">
  <FormGroup
    controlId="stuff"
    bsSize="large"
  >
    <ControlLabel>Stuff</ControlLabel>
    <FormControl
    />
  </FormGroup>
</div>
<div className="testingMore">
  <h1>Additional Stuff</h1>
</div>

标签: javascriptcssreactjsreact-bootstrap

解决方案


您可以创建一个包含表单和标题的元素,并将其放入flex容器中display:flex;

.form-wrapper {
  display: flex;
}

.testingForm {
  max-width: 320px;
}

h1 {
  margin-top: 0;
}
<div class="form-wrapper">
  <div className="testingForm">
    <form>
      Test: <input type="text"/>
    </form>
  </div>
  <div>
    <h1>Additional Stuff</h1>
  </div>
</div>


推荐阅读