input元素与文字对齐

示例代码

<style>
*{margin:0;}
label{vertical-align:middle}
.inputcheckbox{vertical-align:middle;}
body{font-family:tahoma;font-size:12px;}
</style>
<input class="inputcheckbox" name="test" value="1" type="checkbox">
<label>测试文字x</label>
<br/><br/>
<input class="inputcheckbox " name="test2" value="2" type="radio">
<label>测试文字x</label>
<br/><br/>
<input class="inputcheckbox " name="Text1" type="text" />
<label>文字</label>
<input  class="inputcheckbox " name="Text1" type="text" />
<label>文字</label>
<br/><br/>
<label>测试文字</label>
<input   class="inputcheckbox " name="Button1" type="button" value="按钮" />
<br/><br/>
<select class="inputcheckbox " name="Select1">
<option>测试文字</option>
</select>
<label>测试文字</label>
<input class="inputcheckbox " name="test" value="1" type="checkbox">
<label>测试文字x</label>
<br/>
<input class="inputcheckbox " name="test" value="1" type="checkbox">
<label>這是繁體中文</label>
<br/>
<input class="inputcheckbox " name="test" value="1" type="checkbox">
<label>次回から自動的にログイン</label>
<br/>
<input class="inputcheckbox " name="test" value="1" type="checkbox">
<label>English</label>
<br/>
<input class="inputcheckbox " name="test" value="1" type="checkbox">
<label>Чужой компьютер</label>
<br/>
<input class="inputcheckbox " name="test" value="1" type="checkbox">
<label>صفحات من ‏السعودية </label>
<br/>
<input class="inputcheckbox " name="test" value="1" type="checkbox">
<label>회원가입</label>
<br/>
<input class="inputcheckbox" name="test" value="1" type="checkbox">
<label>הפתוח</label>
<br/>

上述代码涵盖了三个问题:

1.单(复)选框和后面的提示文字不对齐,提示文字用label,设置vertical-align:middle;单选会下边框缺失,所以要注意初始设置。

2.IE下文本框默认为22px,如果文本框内要文字居中对齐,需要设置字体为偶数

3.同理,其他国家的语言也可以实现居中对齐

参考引用:http://www.blueidea.com/tech/web/2009/6910.asp

    原文作者:dolinyuan
    原文地址: https://blog.csdn.net/dolin88/article/details/79942393
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞