Bootstrap: Checkboxes / Radio buttons don't vertically align with label text when using a custom font size

Created on 5 May 2015  路  6Comments  路  Source: twbs/bootstrap

Create a customized bootstrap with font-size 20px being the only change.
Any input type checkbox/ radio with label text is viably not aligned

Seems like the generated margin is

input[type="radio"],
input[type="checkbox"] {
  margin: 4px 0 0;
  margin-top: 1px \9;
  line-height: normal;
}

regardless of the base font size
Here is an example :
bootstrap-font-size-20px

margin probably needs to be calculated based on font size...

css

Most helpful comment

I have found a solution:

// Position radios and checkboxes more better
input[type="radio"],
input[type="checkbox"] {
    margin-top: ((@line-height-base - 1)/2) * 1em;
    width: 1em;
    height: 1em;
}

This solution is not only care about font-size, also line-height. Some examples: https://jsfiddle.net/r0m7a2kj/

All 6 comments

Agreed we need to set them by font size, but I'm hesitant to make any changes to v3 to support that just yet. I know it sucks, but for now you'll need to customize that yourself. v4 will have proper scaling of things by typography.

@mdo, is it difficult to send a fix about this issue to a next minor version of Bootstrap 3?

there won't be any new major nor minor versions of Bootstrap 3. all efforts are now focused on version 4, I'm afraid.

@patrickhlauke , so what's about bug fixes? This can be thought as a bug, I think.

I have found a solution:

// Position radios and checkboxes more better
input[type="radio"],
input[type="checkbox"] {
    margin-top: ((@line-height-base - 1)/2) * 1em;
    width: 1em;
    height: 1em;
}

This solution is not only care about font-size, also line-height. Some examples: https://jsfiddle.net/r0m7a2kj/

This bug is also present in v4-beta1 and could be solved for custom checkboxes/radios with

.custom-control {
  align-items: center;
}

but it need additional fix for regular checkboxes/radios too.

Was this page helpful?
0 / 5 - 0 ratings