如何使复选框与表单中的其他输入控件垂直对齐?

时间:2019-06-07 22:13:29

标签: html checkbox bootstrap-4 vertical-alignment

我的复选框当前以这种方式对齐-

enter image description here

我想将其移动到下面的标记/指向的位置-

enter image description here

我正在使用Bootstrap4。以下是我的HTML-

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row form-group">
  <label class="col-md-1 col-form-label" for="director">Director</label>
  <div class="col-md-8">
    <input class="form-control" type="text" id="director" name="director" placeholder="Director">
  </div>
</div>
<div class="row form-group form-check">
  <div class="col">
    <input class="form-check-input" type="checkbox" id="released" name="released">
    <label class="form-check-label" for="released">Released</label>
  </div>
</div>
<div class="row form-group">
  <label class="col-md-1 col-form-label" for="year">Year</label>
  <div class="col-md-8">
    <input class="form-control" type="text" id="year" name="year" placeholder="Year">
  </div>
</div>

1 个答案:

答案 0 :(得分:2)

简单

<div class="row form-group">
    <div class="col-md-11 offset-md-1">
        <div class="form-check">
            <input class="form-check-input" type="checkbox" id="released" name="released">
            <label class="form-check-label" for="released">Released</label>
        </div>
    </div>
</div>


enter image description here

演示: https://jsfiddle.net/davidliang2008/L1krytub/4/

IMO,我认为col-md-1的宽度不足以容纳您的标签。