Search code examples
htmlcsstwitter-bootstrapcheckboxvertical-alignment

Bootstrap form-horizontal vertical alignment of checkboxes without label text


I have changed from Bootstrap 3.0.0 to 3.2.0 this morning because I needed some of the new features for my web application. Everything seemed to work as expected until I observed an issue with the vertical alignment of checkboxes in a .form-horizontal form.

An example is available at http://www.bootply.com/AYN64feYze. The markup for this minimum example is:

<div class="form-horizontal">
    <div class="form-group">
      <label class="col-sm-2 control-label">With label text</label>
          <div class="col-sm-10">
            <div class="checkbox">
              <label>
                  <input type="checkbox"> label text
              </label>
            </div>
          </div>
    </div>
  <div class="form-group">
      <label class="col-sm-2 control-label">Without label text</label>
          <div class="col-sm-10">
            <div class="checkbox">
              <label>
                  <input type="checkbox">
              </label>
            </div>
          </div>
    </div>
</div>

If a checkbox has no following text it is shifted below the row it should appear in.

Is there a solution to this problem? Since I already have the leading label I do not need a following text for my checkboxes. My current workaround is adding text to the <label> that contains the <input type="checkbox"> and use the background color as the font color to hide the text.

Thank you for your help.


Solution

  • I'm not sure if this will affect the rest of your form layout, but the issue seems to be resolved if you change the display attribute of <label> (currently set to inline-block) to:

    label{
        display:inline;
    }
    

    Here's an updated Bootply. Hope this helps! Let me know if you have any questions.