将复选框与多行标签对齐

时间:2013-05-22 15:42:16

标签: html css

请参阅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>

如何对齐:顶部,底部和中间的复选框?

我会用另一个容器并使用定位来做,但有更简单的方法吗?

2 个答案:

答案 0 :(得分:14)

您只需要使用<label>本身的vertical-align属性

http://jsbin.com/oloxes/1/edit(我在此示例中指定了值top

答案 1 :(得分:3)

2015年答案:
由于vertical-align对我不起作用(或不再起作用),所以我就是这样做的:

<!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>

http://jsfiddle.net/8jzss08p/
适用于:Firefox 41,Chrome 45,Internet Explorer 11