Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center align placeholder issue in android

In my android application there is webview to display html. In webview, for input field, we want placeholder to center align. Placing style

-webkit-input-placeholder {text-align: center;}

but placeholder is not aligning center. it's working fine with browser when we test. Could any one help me on it?

like image 419
Pankaj Avatar asked Sep 24 '13 12:09

Pankaj


People also ask

How do you align placeholder text?

In most of the browsers, placeholder texts are usually aligned in left. The selector uses text-align property to set the text alignment in the placeholder. This selector can change browser to browser.

How do you center a placeholder in TextInput react native?

To change TextInput placeHolder alignment with React Native, we can set the textAlign style to 'center' . to align the placeholder at the center of the screen by setting textAlign set to 'center' .


1 Answers

Android has a bug here :(, centering just won't work. You can use this polyfill: https://github.com/diy/jquery-placeholder and it supports the "force" attribute. That attribute makes it run even on browser that "support" placeholder, like android.

$('#myInput').placeholder({force:true});

Then use regular CSS to style the placeholder class provided by the plugin

.placeholder{
  text-align: center;
}
like image 168
Jonathan Rowny Avatar answered Oct 04 '22 20:10

Jonathan Rowny