Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5.0 Safari not vertically centering placeholder in text box

I want to vertically center the text entered in input text boxes on the page.

Typical way to achieve this is to set the line-height and height equal. This works on pre iOS 5.0 Safari.

However; on iOS 5, Safari displays the typed text vertically centered... But the placeholder text and the cursor appear top aligned.

.txtBox {
    line-height: 3em;
    height: 3em;
}

<input type="text" class="txtBox" placeholder="Name"></input>

Anyone else facing this issue?

like image 280
Nirmal Patel Avatar asked Dec 19 '11 08:12

Nirmal Patel


3 Answers

For me there is only one solution that appears close to perfect in all browsers I tested (Chrome, FF, Safari (+iOS), IE10):

line-height: normal;

Solutions like line-height: 100% and line-height: 1; seem to be aligned towards the top of the input, especially in Chrome.

http://jsfiddle.net/5Vc3z/

Comparison:

http://jsfiddle.net/5Vc3z/1/

like image 97
Marcel Avatar answered Sep 21 '22 10:09

Marcel


Setting line-height: 1; seems to fix this.

like image 43
Jesse Avatar answered Sep 19 '22 10:09

Jesse


You should use percentage for the line-height.

.txtBox {
       line-height: 100%;
       height: 3em;
    }
<input type="text" class="txtBox" placeholder="Name"></input>
like image 36
andychukse Avatar answered Sep 21 '22 10:09

andychukse