Html 如何文本对齐此标签文本的中心?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15753746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to text-align center this label text?
提问by jaycodez
How do I vertically align center this text?
如何垂直对齐此文本?
From:
从:
To:
到:
<<p>
<label></label>
<input type="checkbox" id="checkbox" name="checkbox" class="regular-checkbox big-checkbox" value="Yes" checked="checked">
<label for="checkbox" style="margin-right:10px;"></label>Subscribe me to your mailing list for upcoming events, hot offers and deals
</p>
回答by PSL
Try this:-
尝试这个:-
label
{
vertical-align:middle;
}
回答by Explosion Pills
As counter-intuitive as it might seem, you need to add vertical-align: middle
to the element you want to vertically align with, rather than the element you want to be vertically aligned (in this case, the label[for=checkbox]
.
作为反直觉的,因为它看起来,你需要添加vertical-align: middle
到您要垂直对齐的元素用,而不是要垂直对齐的元素(在这种情况下,label[for=checkbox]
。
See a demo here: http://jsfiddle.net/E5CxM/2/
在此处查看演示:http: //jsfiddle.net/E5CxM/2/
回答by What have you tried
Use line-height to make text vertically centered
使用 line-height 使文本垂直居中
label{
line-height: 45px;
height: 45px;
display: inline-block;
}
Here is a simple example of how it works:
这是它如何工作的一个简单示例: