css – 覆盖谷歌Chrome中保存的密码字段的样式

前端之家收集整理的这篇文章主要介绍了css – 覆盖谷歌Chrome中保存的密码字段的样式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在设计一个Web应用程序,一般的风格涉及黑色背景上的白色文本.

这种风格包括使用自定义(黑色)图像进行用户名和密码字段的白色文本.

如果用户使用google chrome登录并选择保存其表单的登录详细信息,则在下次访问时,用户名和密码字段将以浅黄色显示白色文本,几乎不可能读取.这看起来真的很糟糕

如何覆盖此样式,防止Google Chrome更改保存的用户名和密码字段的背景.

  1. <style type="text/css">
  2. input {
  3. border: none;
  4. background: url('darkinput.png');
  5. color: #fff;
  6. }
  7. </style>
  8.  
  9. <input type="text" name="email" id="text" />
  10. <input type="password" name="password" id="text" />

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

  1. input:-webkit-autofill{
  2. background-color: rgb(250,255,189) !important;
  3. background-image: none !important;
  4. }

在下面的网址上有一个问题报告,我鼓励每个读这个的人投票支持

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

解决方法

要完全禁用自动完成(并因此删除样式问题),您可以尝试:
  1. <form autocomplete="off">
  2. ...
  3. </form>

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

  1. if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {
  2. $(window).load(function(){
  3. $('input:-webkit-autofill').each(function(){
  4. var text = $(this).val();
  5. var name = $(this).attr('name');
  6. $(this).after(this.outerHTML).remove();
  7. $('input[name=' + name + ']').val(text);
  8. });
  9. });}

猜你在找的CSS相关文章