简体   繁体   English

垂直对齐标签

[英]Align label vertically

I have to center vertically a label with a textbox. 我必须垂直放置带有文本框的标签。 This is the fiddle http://jsfiddle.net/TAavK/ . 这是小提琴http://jsfiddle.net/TAavK/ The label is in the top of the input, but I want to put this in the center of this. 标签在输入的顶部,但是我想将其放在输入的中心。 How can I do? 我能怎么做?

    <form class="pure-form pure-form-aligned">
        <div class="pure-control-group">
            <label for="txtUsuario" class="clase">User</label>
             <input type="text" name="txtUsuario" />
        </div>
        <div class="pure-control-group">
           <label for="txtPass" class="clase">Password</label>
           <input type="password" name="txtPass" />
        </div>
    </form>

.pure-form-aligned .pure-control-group {
    margin-bottom: 0.5em;
}
.pure-form-aligned .pure-control-group label {
    display: inline-block;
    margin: 0 1em 0 0;
    text-align: right;
    vertical-align: middle;
    width: 15em;
}
label.clase {
    float: left;
}
input {
    width: 30%;
    border: 1px solid #CCCCCC;
    border-radius: 4px;
    box-shadow: 0 1px 3px #DDDDDD inset;
    box-sizing: border-box;
    display: inline-block;
    padding: 0.5em 0.6em;
    vertical-align: middle;
    line-height: normal;
    font-size: 100%;
    margin: 0;
}

Remove this 删除这个

label.clase {
    float: left;
}

JSfiddle Demo JSfiddle演示

Try it 试试吧

<form class="pure-form pure-form-aligned">
    <div>
        <div class="pure-control-group">
            <label for="txtUsuario" class="clase">User</label>
        </div>
        <div class="pure-control-group">
            <input type="text" name="txtUsuario" />
        </div>
    </div>
    <div>
        <div class="pure-control-group">
            <label for="txtPass" class="clase">Password</label>
        </div>
        <div class="pure-control-group">
            <input type="password" name="txtPass" />
        </div>
    </div>
</form>

Change only this css class 仅更改此CSS类

.pure-form-aligned .pure-control-group {
    margin-bottom: 0.5em;
    vertical-align: middle;
    display: table-cell;
}

http://jsfiddle.net/TAavK/9/ http://jsfiddle.net/TAavK/9/

write this: 写这个:

   label.clase 
   {
     margin: auto;
     top: 0; left: 0; bottom: 0; right: 0;
   }

Watch here 在这里观看

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

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