覆盖Google Chrome中保存的密码字段的样式

Mat*_*hew 16 css google-chrome

我正在设计一个Web应用程序,一般风格涉及深色背景上的白色文本.

此样式包括使用自定义(暗)图像作为用户名和密码字段,并带有白色文本.

如果用户使用谷歌浏览器登录并选择保存表单的登录详细信息,则在下次访问时,用户名和密码字段将显示为带有白色文本的淡黄色,使其几乎无法读取.这看起来很糟糕.

我将如何重写此样式,防止Google Chrome更改已保存的用户名和密码字段的背景.

<style type="text/css">
  input {
    border: none;
    background: url('darkinput.png');
    color: #fff;
  }
</style>

<input type="text" name="email" id="text" /> 
<input type="password" name="password" id="text" />
Run Code Online (Sandbox Code Playgroud)

编辑:当前(google-chrome v11.0.696.57)用户代理样式表包含!重要覆盖以设置以下两项:

input:-webkit-autofill{
  background-color: rgb(250, 255, 189) !important;
  background-image: none !important;
}
Run Code Online (Sandbox Code Playgroud)

在下面的网址上有一个问题报告,我鼓励所有阅读此内容的人投票支持:

http://code.google.com/p/chromium/issues/detail?id=46543

Cre*_*voc 8

要完全禁用自动完成(因此删除样式问题),您可以尝试这样做:

<form autocomplete="off">
...
</form>
Run Code Online (Sandbox Code Playgroud)

然而,另一种可能性是在页面加载后使用jquery删除样式.

if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
$(window).load(function(){
    $('input:-webkit-autofill').each(function(){
        var text = $(this).val();
        var name = $(this).attr('name');
        $(this).after(this.outerHTML).remove();
        $('input[name=' + name + ']').val(text);
    });
});}
Run Code Online (Sandbox Code Playgroud)


n1k*_*kou 5

只需设置阴影即可解决:

input:-webkit-autofill { 
  -webkit-box-shadow:200px 200px 100px white inset; 
  box-shadow:200px 200px 100px white inset; 
}
Run Code Online (Sandbox Code Playgroud)