Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align checkbox with a multi line label

Tags:

html

css

See http://jsbin.com/ocutob/1/edit

<span>
  <input checked="checked" type="checkbox" value="1">
  <label>test test test test test test test test test test test test </label>
</span>

How can align the checkbox at the: top, bottom and middle?

I would do it with another container and using positioning, but is there a simpler way?

like image 228
sites Avatar asked May 22 '13 15:05

sites


1 Answers

Answer for 2015:
Since vertical-align doesn't work for me (or not anymore), here's how I do it:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Radiobutton labels aligned</title>
<style type="text/css">
    div { display:table-row; }
    div span { display:table-cell; vertical-align:middle; } /* You can omit the entire span if you don't want the radiobutton vertically centered */
    div label { display:table-cell; }
</style>
</head>
<body>
<form>
<div>
    <span><input type="checkbox" id="a"></span>
    <label for="a">First button's label<br>First button's label</label>
</div>
<div>
    <span><input type="checkbox" id="b"></span>
    <label for="b">Second button's label</label>
</div>
<input type="checkbox" id="c"><label for="c">For comparison: Standard-Label</label>
</form>
</body>
</html>

See http://jsfiddle.net/8jzss08p/
Works in: Firefox 41, Chrome 45, Internet Explorer 11

like image 174
Thomas Landauer Avatar answered Sep 22 '22 06:09

Thomas Landauer