2015-05-05 76 views
0

Fiddle垂直对齐输入?

我需要垂直对齐其父项中的输入以及它的标签。

我已经试过了表格单元格的方法,但没有运气:

<div class="holder"> 
    <label>Text input: </label> 
    <input type="text" class="input" /> 
</div> 

.holder{ 
    height: 400px; 
    width: 400px; 
    background: tomato; 
    display: table; 
} 

.input{ 
    display: table-cell; 
    vertical-align: middle; 
} 

回答

2

没有必要对表格布局,因为容器有固定的高度,使用line-height属性,而不是你的.holder元素:

line-height:400px; 

JSFiddle

0

.holder表格单元格。

.holder{ 
    height: 400px; 
    width: 400px; 
    background: tomato; 
    display: table-cell; 
    vertical-align: middle; 
} 

.input{ 
    /* remove the styles */ 
} 

Updated Fiddle