Android中心对齐占位符问题

6

我的安卓应用中有一个webview来显示html页面。 在webview中,对于输入框,我们想要让占位符居中对齐。 样式代码如下:

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

但占位符未对齐中心。在浏览器测试时,其工作良好。有人能帮忙吗?

2个回答

3

Android在这里有一个bug :(,居中对齐就是不起作用。您可以使用这个polyfill:https://github.com/diy/jquery-placeholder,它支持“force”属性。该属性使其在即使是像android这样“支持”占位符的浏览器上也能运行。

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

然后使用常规CSS来样式化插件提供的占位符类。
.placeholder{
  text-align: center;
}

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

请尝试这个。

或者

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

抱歉给您带来不便,正如您所建议的那样,我已经编辑了我的问题。谢谢。 - Pankaj
2
没有运气,它在安卓上没有生效,仍然在安卓设备上显示为左对齐。 - Pankaj
@Pankaj 兄,我给你发了一个新的答案,请试一下。 - Kanwaljit Singh
请查看此链接:https://dev59.com/Hms05IYBdhLWcg3wNPM3 - Kanwaljit Singh
有没有其他建议?我也遇到了完全相同的问题。它在浏览器中居中,但在 Android WebView 中不居中。 - David Hahn

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接