Bootstrap 4表单格式

时间:2017-11-07 18:46:28

标签: html css twitter-bootstrap

好吧,这开始让我恼火。我是第一次在bootstrap 4中工作,并且我试图在没有添加太多div的情况下获得格式化表单。

我试图让标签位于输入字段旁边。我尝试过使用花车,col和其他一些东西,但由于某种原因,他们不想听我的话!

请帮助你疯了。

我的HTML

<form class='form-group'>
    <div class='container'>
        <div class='row'>
            <div class='col-6'>
                <div class="form-group">
                    <label class='col-form-label formLabel'>Customer Name:</label>
                    <input class='form-control formInput' name='customerName' />
                </div>
                <div class="form-group">
                    <label class='formLabel'>Phone Number:</label>
                    <input class='form-control formInput' name='phoneNumber' />
                </div>
                <div class="form-group">
                    <label class='formLabel'>Email:</label>
                    <input class='form-control formInput' name='emailAddress' />
                </div>
            </div>
        </div>
        <div class='col-6'>
            <div class="form-group">
                <label class='col-form-label formLabel'>Customer Name:</label>
                <input class='form-control formInput' name='customerName' />
            <div class="form-group">
                <label class='formLabel'>Phone Number:</label>
                <input class='form-control formInput' name='phoneNumber' />
            </div>
            <div class="form-group">
                <label class='formLabel'>Email:</label>
                <input class='form-control formInput' name='emailAddress' />
            </div>
        </div>
    </div>

</div>

    <!-- Modal footer -->
    <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button class='btn btn-success'>Save Changes</button>
    </div>
  </form>

https://www.bootply.com/b8B4C07XB7

可能的副本来自四年前。不同版本的bootstrap。

2 个答案:

答案 0 :(得分:0)

只需在表单标记内添加form-inline类,即可看到魔法!

<form class="form-group form-inline">
                <div class="container">
                    <div class="row">
                        <div class="col-6">
                            <div class="form-group">
                                <label class="col-form-label formLabel">Customer Name:</label>
                                <input class="form-control formInput" name="customerName">
                            </div>
                        </div>
                    </div>
                </div>
            </form>

答案 1 :(得分:0)

form-inline用于内联表单。它适用于大于768px的视口,因此将片段结果窗口展开到全屏以查看实际呈现的内联形式。

@import url("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css");
.formLabel {
  text-align: left;
}

.formInput {
  text-align: right;
}
<form class='form-inline'>
  <div class="form-group">
    <label class='col-form-label formLabel'>Customer Name:</label>
    <input class='form-control formInput' name='customerName' />
  </div>
  <div class="form-group">
    <label class='formLabel'>Phone Number:</label>
    <input class='form-control formInput' name='phoneNumber' />
  </div>
  <div class="form-group">
    <label class='formLabel'>Email:</label>
    <input class='form-control formInput' name='emailAddress' />
  </div>
  <div class="form-group">
    <label class='col-form-label formLabel'>Customer Name:</label>
    <input class='form-control formInput' name='customerName' />
    <div class="form-group">
      <label class='formLabel'>Phone Number:</label>
      <input class='form-control formInput' name='phoneNumber' />
    </div>
    <div class="form-group">
      <label class='formLabel'>Email:</label>
      <input class='form-control formInput' name='emailAddress' />
    </div>
  </div>
  <!-- Modal footer -->
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    <button class='btn btn-success'>Save Changes</button>
  </div>
</form>