0

我在模式框内有表单,其中包含输入字段和纯文本的组合。我想知道这种情况下引导程序的一般规则是什么。元素应该如何组织?我应该使用<div class='form-group'>所有东西还是可以使用<div class='row'><div class='col-xs-12'>例如?这是我到目前为止所拥有的:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/js/bootstrap.min.js" integrity="sha384-7aThvCh9TypR7fIc2HV4O/nFMVCBwyIUKL8XCtKE+8xgCgl/PQGuFsvShjr74PBp" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css" integrity="sha384-PDle/QlgIONtM1aqA2Qemk5gPOE7wFq8+Em+G/hmo5Iq0CCmYZLv3fVRDJ4MMwEA" crossorigin="anonymous">

<div id="myModal" class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h5 class="modal-title">Title</h5>
      </div>
      <div class="modal-body">
        <form id='frm_my'>
          <div class='row'>
            <div class='col-xs-12'>Frm validation rules in description here. Dummy text for testing purpuse.</div>
          </div>
          <div class='row'>
            <div class='col-xs-1'><input type='checkbox' name='check' id='check'></div>
            <div class='col-xs-11'>Field 1 description with some dummy text (example)</div>
          </div>
          <div class='row'>
            <div class='form-group'><label for='comment'>Comment:</label><textarea class='form-control' rows='2' id='comment'></textarea></div>
          </div>
          <div class='row'>
            <div class='col-xs-12'>Click on the Accept button if you would like to save the form data. <b>Accept</b>.</div>
          </div>
          <div class='row'>
            <div class='col-xs-12'>To cancel this screen and return to the display screen, click <b>Cancel</b></div>.
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Accept</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
      </div>
    </div>
  </div>
</div>

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>

另外,我想知道是否有一种方法可以在表单周围添加填充,因此它不在模态框的边缘旁边?谢谢你。

4

1 回答 1

1

JS小提琴

(从代码看来,使用了 Bootstrap 4.3.0。因此代码中的类col-xs-12更改为col-12

TL;可以使用DR网格。最好用它form-group来包装表单元素(这就是 Bootstrap 提供它们的原因!)。

网格可以在模态中使用,如文档中所述。(这适用于 3.4,此处适用于 v4.0 )您可能希望在需要 2 列布局时使用它。

表单元素更好地被包裹起来,form-control并且必须对<input>type checkbox, file,进行特殊处理radio。(所以我们有 Bootstrap 的默认样式和定位)。文档

要在表单中使用网格,还可以查看Form Grid

通过添加样式后form-group,如果您想要左右更多的填充,您还可以添加<div class='container'>.

于 2019-02-12T14:20:59.063 回答