Skip to content

Bootstrap 4 form-check alignment with horizontal label #24844

Closed

Description

@migliori

Vertical alignment between a main horizontal label and checkboxes or radio is wrong.

The main label has the .col-form-label class, which adds a padding-top: padding-top: calc(.375rem + 1px)

The radio buttons have no padding top, so they're too high.

I made this pen to show the issue: https://codepen.io/migli/pen/yPKbwL

The pen also includes a simple css proposal to resolve it.

Activity

  1. added
    cssSass sources or compiled CSS
    v4v4, the frozen docs on gh-pages
    on Nov 21, 2017
  2. ysds commented on Nov 22, 2017

    @ysds
    Contributor

    A horizontal label and control vertical alighment issue can be confirmed here as well. (The "Radios" row)
    I think we should not solve this by CSS because CSS will be more complex and more difficult to understand the responsive behaveor. When resize a window to mobile size on your codepen, you can see a slightly larger spacing between the label and first checkbox.

    To resolve this issue, just add pt-{breakpoint}-0 to .col-form-label (or .col-form-legend).

    <form>
      <fieldset class="form-group">
        <div class="row">
          <legend class="col-form-legend col-sm-2 pt-sm-0">Radios</legend>
          <div class="col-sm-10">                 ^^^^^^^
            <div class="form-check">...</div>
  3. migliori commented on Nov 22, 2017

    @migliori
    Author

    The mobile size spacing can be easily solved with a media query (I edited my pen)

    My first idea was yours, but If you remove the label's top padding the label is too close from the previous element, it breaks the vertical alignment: https://codepen.io/migli/pen/mqxQjo

    I also noticed that the example code was a bit inconsistent.

    The main label for radio is <legend class="col-form-legend col-sm-2">Radios</legend> while the checkbox's main label is <div class="col-sm-2">Checkbox</div>

  4. mdo commented on Nov 27, 2017

    @mdo
    Member

    Perhaps we instead advise folks to simply not use that class on form groups with radios and checks? https://codepen.io/anon/pen/BmORRj

  5. migliori commented on Nov 28, 2017

    @migliori
    Author

    it's a possibility, but it breaks the regularity of the vertical alignment of labels.

  6. mdo commented on Nov 28, 2017

    @mdo
    Member

    The regularity of the alignment isn't my concern I think, and I don't imagine it's the concern of anyone else reporting this issue. The more important part is that this one label matches it's inputs.

  7. migliori commented on Nov 28, 2017

    @migliori
    Author

    it's up to you

  8. added a commit that references this issue on Nov 28, 2017
    98755f0
  9. self-assigned this
    on Nov 28, 2017
  10. added
    has-prAn open pull request addresses it
    on Nov 28, 2017
  11. added a commit that references this issue on Nov 29, 2017
    a649c7f
  12. added a commit that references this issue on Dec 1, 2017
    ccf3fb2
  13. added a commit that references this issue on Dec 2, 2017
    9de141f
  14. added a commit that references this issue on Dec 8, 2017
    278a4bc
  15. added a commit that references this issue on Dec 30, 2017
    ea1c866
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

cssSass sources or compiled CSShas-prAn open pull request addresses itv4v4, the frozen docs on gh-pages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions