Center align placeholder issue in android

廉价感情. 提交于 2019-12-06 01:38:57

问题


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?


回答1:


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;
}



回答2:


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

Try this.

Or

<!DOCTYPE html>
<html>
<head>
    <style>
        input::-webkit-input-placeholder
        {
            text-align: center;
        }
    </style>
</head>
<body>
    <input type="text" placeholder="asdf" />
</body>
</html>


来源:https://stackoverflow.com/questions/18982290/center-align-placeholder-issue-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!