Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 form checkbox label doesn't align with checkbox input in Chromium + Firefox

In both chrome and firefox:

  • form-inline causes the label to be shifted downwards and the space between the checkbox and the label is narrower than when using form-horizontal.
  • form-horizontal displays perfectly

Here's a demo in jsFiddle

Here's some code:

<form class="form-inline">     <div class="checkbox">         <label>             <input type="checkbox"/> Test againn         </label>     </div> </form> 

Here's a screenshot:

screenshot

Is there a way to make the checkboxes all aligned correctly in both browsers or am I missing something?

like image 567
user21398 Avatar asked Jun 25 '14 01:06

user21398


People also ask

How do you align checkboxes and their labels consistently cross browsers?

Checkbox inputs need to align vertically with the label text similarly (if not identically) across all browsers. If the label text wraps, it needs to be indented (so no wrapping down underneath the checkbox).

How do I insert a checkbox and label on the same line?

Method 1: By making the position of checkbox relative, set the vertical-align to the middle can align the checkboxes and their labels. Here, we have made the position of the checkbox relative to the label. So the checkboxes are aligned according to the label.

How can I customize a bootstrap checkbox?

To create a custom checkbox, wrap a container element, like <div>, with a class of . custom-control and . custom-checkbox around the checkbox.

How do you make a checkbox inline?

Use . checkbox-inline class to a series of checkboxes for controls to appear on the same line.

How do I align a checkbox to the bottom in HTML?

<form> <div> <label> <input type="checkbox" /> Label text </label> </div> </form> Set the vertical-align property to “bottom”, which is consistent across browsers. Set the position property to “relative” to place the element relative to its normal position.

How do I add a checkbox to the label?

Place “checkbox” input type in the <label> element. <form> <div> <label> <input type="checkbox" /> Label text </label> </div> </form>

What is a checkbox and what is it for?

The checkbox is one of the HTML forms that is used on every website. How to align the checkbox and its label? This is a question that developers frequently ask.

Is it possible to get vertical form for checkboxes?

yes, but if you re-size your browser to xs size you will not get "vertical form" for your checkboxes, it will remain to be inlined. In my case none of the answers resolved the issue.


2 Answers

This is actually an issue in all browsers (that I've tested)

Here's a screenshot - I added a grey border so it's easier to tell that it's not lining up.

screenshot

Here's a demo that reproduces the issue

The issue occurs when the inline form is on a screen that is larger than 768px.

Particularly, the thing that messes up the alignment is from this line of forms.less (which was introduced with this commit):

float: none; 

Naively, setting this value back to float: left seems to fix the problem, but I'm not sure what other issues may arise.

@media (min-width: 768px) {     .form-inline .radio input[type="radio"],      .form-inline .checkbox input[type="checkbox"] {         float: left;         margin-right: 5px;     } } 

Here's a working version of your code with these changes

Other than that, you'd just have to tweak the CSS

like image 145
KyleMit Avatar answered Oct 10 '22 11:10

KyleMit


I got mine works after changing radio or checkbox to radio-inline or checkbox-inline class

http://jsfiddle.net/gn9Up/57/

like image 32
DagicCross Avatar answered Oct 10 '22 12:10

DagicCross