Checkbox alignment in Internet Explorer, Firefox and Chrome

Posted by Andrej on Stack Overflow See other posts from Stack Overflow or by Andrej
Published on 2011-01-13T07:52:32Z Indexed on 2011/01/15 18:53 UTC
Read the original article Hit count: 239

Filed under:
|
|
|
|

Checkbox alignment with its label (i.e., vertical centering) cross different web browsers makes me crazy. Pasted below is standard html code:

<label for="ch"><input id="ch" type="checkbox">My Checkbox</label>

I tested different CSS tricks (e.g., link 1, link 2); most solutions works fine in FF, but are completely off in Chrome or IE8.

I'm looking for any references or pointers to solve this issue. Thanks in advance.

EDIT

According to Elq suggestion I modified the HTML

<div class="row">
<input type="checkbox" id="ch1" />
<label for="ch1">Test</label>
</div>

and CSS

.row{
  display: table-row;
}

label{
  display: table-cell;
  vertical-align: middle;
}

Works now in Firefox, Internet Explorer 8, and Chrome on Windows. Fails on Firefox and Chrome on Linux. Also works in Firefox and Safari on Mac, but fails on Chrome.

© Stack Overflow or respective owner

Related posts about html

Related posts about css