简体   繁体   English

html-CSS:如何在标签标签中垂直对齐文本和表单元素?

[英]html - CSS: How can I vertically align text and form elements in a label tag?

I have a <label> in my html document, where I have some text and form elements in it. 我的html文档中有一个<label> ,其中有一些文本和表单元素。
How can I vertically align them in middle? 如何在中间垂直对齐它们?

<label>
    Show
    <select name="list_length" size="1" aria-controls="admin_id">
        <option value="10" selected="selected">10</option>
        <option value="25">25</option>
        <option value="50">50</option>
        <option value="100">100</option>
    </select>
    entries per page.
</label>

<label>
    Search:
    <input type="text" aria-controls="id_281">
</label>

I have added this in the css too: 我也在CSS中添加了它:
display: inline-block and vertical-align: middle display: inline-blockvertical-align: middle

Set height and line height on the same value: 将高度和线高设置为相同的值:

height: 50px;
line-height: 50px;

Or try this vertical centering: 或尝试以下垂直居中:

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

HTML 的HTML

<label>
    <span>Show</span>
    <select name="list_length" size="1" aria-controls="admin_id">
        <option value="10" selected="selected">10</option>
        <option value="25">25</option>
        <option value="50">50</option>
        <option value="100">100</option>
    </select>
    <span>entries per page.</span>
</label>

<label>
    <span>Search:</span>
    <input type="text" aria-controls="id_281">
</label>

CSS 的CSS

label span,
label input,
label select{
    display: inline-block;
    vertical-align: middle;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM