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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:04:43  来源:igfitidea点击:

How to text-align center this label text?

htmlcssforms

提问by jaycodez

How do I vertically align center this text?

如何垂直对齐此文本?

From:

从:

enter image description here

在此处输入图片说明

To:

到:

enter image description here

在此处输入图片说明

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

http://jsfiddle.net/JoshSalway/E5CxM/

http://jsfiddle.net/JoshSalway/E5CxM/

回答by PSL

Try this:-

尝试这个:-

http://jsfiddle.net/AFGMf/

http://jsfiddle.net/AFGMf/

 label
    {
        vertical-align:middle;
    }

回答by Explosion Pills

As counter-intuitive as it might seem, you need to add vertical-align: middleto 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:

这是它如何工作的一个简单示例:

http://jsfiddle.net/E5CxM/10/

http://jsfiddle.net/E5CxM/10/