在我正在处理的表单上,Chrome浏览器会自动填写电子邮件和密码字段。 很好,但是Chrome将背景颜色更改为浅黄色。

我正在研究的设计是在深色背景上使用浅色文本,因此这确实弄乱了表单的外观-我有明显的黄色框和几乎看不见的白色文本。 聚焦后,场将恢复正常。

是否可以停止Chrome更改这些字段的颜色?


#1楼

目前可能的解决方法是在内部阴影中设置“强”的阴影:

input:-webkit-autofill {-webkit-box-shadow:0 0 0 50px white inset; /* Change the color to your own background color */-webkit-text-fill-color: #333;
}input:-webkit-autofill:focus {-webkit-box-shadow: /*your box-shadow*/,0 0 0 50px white inset;-webkit-text-fill-color: #333;
}

#2楼

这可以正常工作,您可以在输入框内更改输入框样式以及文本样式:

在这里您可以使用任何颜色,例如white#DDDrgba(102, 163, 177, 0.45) #DDD rgba(102, 163, 177, 0.45)

但是transparent在这里行不通。

/* Change the white to any color ;) */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active  {-webkit-box-shadow: 0 0 0 30px white inset !important;
}

此外,您可以使用它来更改文本颜色:

/*Change text in autofill textbox*/
input:-webkit-autofill {-webkit-text-fill-color: yellow !important;
}

建议:不要使用成百上千的模糊半径。 这没有任何好处,并且可能会使处理器负载在较弱的移动设备上。 (对于实际的外部阴影也是如此)。 对于高度为20px的普通输入框,可以完美覆盖30px的“模糊半径”。


#3楼

如前所述,对我来说,插入-webkit-box-shadow效果最佳。

/* Code witch overwrites input background-color */
input:-webkit-autofill {-webkit-box-shadow: 0 0 0px 1000px #fbfbfb inset;
}

还要编写代码段来更改文本颜色:

input:-webkit-autofill:first-line {color: #797979;
}

#4楼

我放弃!

由于无法通过自动完成功能更改输入的颜色,因此我决定使用jQuery将其全部禁用以用于Webkit浏览器。 像这样:

if (/webkit/.test(navigator.userAgent.toLowerCase())) {$('[autocomplete="on"]').each(function() {$(this).attr('autocomplete', 'off');});
}

#5楼

Daniel Fairweather的解决方案(要删除Chrome自动完成功能的输入背景色? )(我很想赞成他的解决方案,但仍需要15个代表)效果很好。 大多数提议的解决方案之间确实存在巨大差异:您可以保留背景图片! 但是稍作修改(只需Chrome检查)

您需要记住, 它仅适用于可见区域

因此,如果您在表单中使用$ .show(),则需要在show()事件后运行此代码。

我的完整解决方案(我有一个用于登录表单的显示/隐藏按钮):

 if (!self.isLoginVisible()) {var container = $("#loginpage");container.stop();self.isLoginVisible(true);if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {var documentForms = document.forms;for (i = 0; i < documentForms.length; i++) {for (j = 0; j < documentForms[i].elements.length; j++) {var input = documentForms[i].elements[j];if (input.type == "text" || input.type == "password" || input.type == null) {var text = input.value;input.focus();var event = document.createEvent('TextEvent');event.initTextEvent('textInput', true, true, window, 'a');input.dispatchEvent(event);input.value = text;input.blur();}}}}} else {self.hideLogon();}

再次抱歉,我希望将其作为评论。

如果您愿意,我可以在我使用它的网站上放置一个链接。


#6楼

没有一种解决方案对我有用,插入阴影对我不起作用,因为输入具有覆盖页面背景的半透明背景。

所以我问自己:“ Chrome如何确定在给定页面上应自动填充的内容?”

“它会查找输入ID,输入名称吗?表单ID?表单动作?”

通过对用户名和密码输入的实验,发现只有两种方法会导致Chrome无法找到应自动填充的字段:

1)将密码输入置于文本输入之前。 2)给他们相同的名称和ID ...或根本不给名称和ID。

页面加载后,可以使用javascript动态更改页面上输入的顺序,也可以动态为其提供名称和ID。

而且Chrome不知道该怎么击...自动完成功能已损坏!

疯狂破解,我知道。 但这对我有用。

Chrome 34.0.1847.116,OSX 10.7.5


#7楼

除此之外:

input:-webkit-autofill{
-webkit-box-shadow: 0 0 0px 1000px white inset;
}

您可能还想添加

input:-webkit-autofill:focus{
-webkit-box-shadow: 0 0 0px 1000px white inset, 0 0 8px rgba(82, 168, 236, 0.6);
}

否则,当您单击输入时,黄色将重新出现。 对于焦点,如果您使用的是引导程序,则第二部分用于突出显示边框0 0 8px rgba(82,168,236,0.6);

这样,它将看起来像任何引导输入。


#8楼

由于这种着色行为来自WebKit,因此已按设计进行了设计。 它使用户可以了解已预填充的数据。 错误1334

您可以执行以下操作(或在特定的表单控件上关闭自动完成功能:

<form autocomplete="off">
...
</form

或者,您可以通过执行以下操作来更改自动填充的颜色:

input:-webkit-autofill {color: #2a2a2a !important;
}

请注意,正在跟踪一个错误,该漏洞可以再次运行: http : //code.google.com/p/chromium/issues/detail?id=46543

这是WebKit的行为。


#9楼

对于使用指南针的用户:

@each $prefix in -webkit, -moz {@include with-prefix($prefix) {@each $element in input, textarea, select {#{$element}:#{$prefix}-autofill {@include single-box-shadow(0, 0, 0, 1000px, $white, inset);}}}
}

#10楼

我有一个更好的解决方案。

将背景设置为如下所示的另一种颜色并不能解决我的问题,因为我需要一个透明的输入字段

-webkit-box-shadow: 0 0 0px 1000px white inset;

因此,我尝试了其他一些方法,然后想到了:

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {transition: background-color 5000s ease-in-out 0s;
}

#11楼

以上所有答案均有效,但确实有其错误。 下面的代码是上面两个答案的结合,可以完美工作而不会闪烁。

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {transition: background-color 5000s ease-in-out 0s;-webkit-box-shadow: 0 0 0px 1000px #fff inset;
}

#12楼

这是我的解决方案,我使用了过渡和过渡延迟,因此我可以在输入字段上使用透明背景。

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {-webkit-transition: "color 9999s ease-out, background-color 9999s ease-out";-webkit-transition-delay: 9999s;
}

#13楼

试试这个:与上面的@ Nathan-white答案相同,但有一些细微调整。

/* For removing autocomplete highlight color in chrome (note: use this at bottom of your css file). */input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {transition: all 5000s ease-in-out 0s;transition-property: background-color, color;
}

#14楼

萨斯

input:-webkit-autofill&,&:hover,&:focus,&:activetransition-delay: 9999stransition-property: background-color, color

#15楼

试试这个隐藏自动填充样式

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:active,
input:-webkit-autofill:focus {background-color: #FFFFFF !important;color: #555 !important;-webkit-box-shadow: 0 0 0 1000px white inset !important;-webkit-text-fill-color: #555555 !important;}

#16楼

我有一个问题,我不能使用盒子阴影,因为我需要输入字段透明。 这有点hack,但是纯CSS。 将过渡设置为非常长的时间。

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
transition: background-color 50000s ease-in-out 0s, color 5000s ease-in-out 0s;
}

#17楼

先前添加盒形阴影的解决方案非常适合需要纯色背景的人。 添加过渡的另一种解决方案是可行的,但是必须设置持续时间/延迟意味着它将在某个时候再次显示。

我的解决方案是改用关键帧,这样它将始终显示您选择的颜色。

@-webkit-keyframes autofill {to {color: #666;background: transparent;}
}input:-webkit-autofill {-webkit-animation-name: autofill;-webkit-animation-fill-mode: both;
}

Codepen示例: https ://codepen.io/-Steve-/pen/dwgxPB


#18楼

不幸的是,上述解决方案在2016年(问题提出的第二年)对我没有任何作用

因此,这是我使用的主动解决方案:

function remake(e){var val = e.value;var id = e.id;e.outerHTML = e.outerHTML;document.getElementById(id).value = val;return true;
}<input id=MustHaveAnId type=text name=email autocomplete=on onblur="remake(this)">

基本上,它在保存值的同时删除标签,然后重新创建它,然后放回该值。


#19楼

这是完成此任务的复杂解决方案。

 (function($){ if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) { $('input, select').on('change focus', function (e) { setTimeout(function () { $.each( document.querySelectorAll('*:-webkit-autofill'), function () { var clone = $(this).clone(true, true); $(this).after(clone).remove(); updateActions(); }) }, 300) }).change(); } var updateActions = function(){};// method for update input actions updateActions(); // start on load and on rebuild })(jQuery) 
 *:-webkit-autofill, *:-webkit-autofill:hover, *:-webkit-autofill:focus, *:-webkit-autofill:active { /* use animation hack, if you have hard styled input */ transition: all 5000s ease-in-out 0s; transition-property: background-color, color; /* if input has one color, and didn't have bg-image use shadow */ -webkit-box-shadow: 0 0 0 1000px #fff inset; /* text color */ -webkit-text-fill-color: #fff; /* font weigth */ font-weight: 300!important; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" name="name" autocomplete="name"/> <input type="email" name="email" autocomplete="email"/> 

#20楼

如果您想防止Google chrome自动填充但它有点“弯刀”,我有一个解决方案,只需删除google chrome添加到这些输入字段的类,然后将值设置为“”即可(如果您不需要显示)加载后存储数据。

$(document).ready(function () {setTimeout(function () {var data = $("input:-webkit-autofill");data.each(function (i,obj) {$(obj).removeClass("input:-webkit-autofill");obj.value = "";});},1);
});

#21楼

简单,只需添加,

    autocomplete="new-password"

到密码字段。


#22楼

经过2个小时的搜索,似乎Google仍然以某种方式覆盖了黄色,但我为此提供了解决方案。 那就对了。 它也将适用于悬停,聚焦等。 您所要做的就是在其中添加!important。

 input:-webkit-autofill,input:-webkit-autofill:hover,input:-webkit-autofill:focus,input:-webkit-autofill:active {-webkit-box-shadow: 0 0 0px 1000px white inset !important;}

这将完全消除输入字段中的黄色


#23楼

如果您想保持自动完成功能不变,可以使用一些jQuery删除Chrome的样式。 我在这里写了一篇简短的文章: http : //www.benjaminmiles.com/2010/11/22/fixing-google-chromes-yellow-autocomplete-styles-with-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);});
});}

#24楼

Google Chrome用户代理会阻止开发人员使用CSS ,因此要更改autofill UI必须使用以下其他属性:

input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {-webkit-box-shadow: 0 0 0 1000px #d500ff inset !important;/*use inset box-shadow to cover background-color*/-webkit-text-fill-color: #ffa400 !important;/*use text fill color to cover font color*/
}

#25楼

我有一个使用CSS过滤器的纯CSS解决方案。

filter: grayscale(100%) brightness(110%);

灰度滤镜将黄色替换为灰色,然后亮度消除了灰色。

请参阅CODEPEN


#26楼

这为我工作:

padding: 5px;
background-clip: content-box;

#27楼

这将适用于输入,文本区域,并在正常,悬停,焦点和活动状态下进行选择。

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
textarea:-webkit-autofill:active,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus,
select:-webkit-autofill:active,
{-webkit-box-shadow: 0 0 0px 1000px white inset !important;
}

这是针对使用SASS / SCSS的人员的上述解决方案的SCSS版本。

input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill
{&, &:hover, &:focus, &:active{-webkit-box-shadow: 0 0 0px 1000px white inset !important;}
}

#28楼

这对我有用。

.input:-webkit-autofill {transition: background-color 5000s ease-in-out 0s;}


#29楼

增加一小时的延迟将暂停输入元素上的所有CSS更改。
这比添加过渡动画或内部阴影更好。

input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill{transition-delay: 3600s;
}

#30楼

这对我有用(Chrome 76已测试)

input:-internal-autofill-selected {background-color: transparent;
}

#31楼

谢谢本杰明!

Mootools解决方案有点棘手,因为我无法通过使用$('input:-webkit-autofill')来获取字段,因此,我使用了以下内容:

if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {window.addEvent('load', function() {setTimeout(clearWebkitBg, 20);var elems = getElems();for (var i = 0; i < elems.length; i++) {$(elems[i]).addEvent('blur', clearWebkitBg);}});
}
function clearWebkitBg () {var elems = getElems();for (var i = 0; i < elems.length; i++) {var oldInput = $(elems[i]);var newInput = new Element('input', {'name': oldInput.get('name'),'id': oldInput.get('id'),'type': oldInput.get('type'),'class': oldInput.get('class'),'value': oldInput.get('value')});var container = oldInput.getParent();oldInput.destroy();container.adopt(newInput);}
}
function getElems() {return ['pass', 'login']; // ids
}

#32楼

我已经开发了使用JavaScript而不使用JQuery的另一个解决方案。 如果您觉得这有用或决定重新发布我的解决方案,我只要求您输入我的名字。 请享用。 –丹尼尔·费尔威瑟

var documentForms = document.forms;for(i = 0; i < documentForms.length; i++){for(j = 0; j < documentForms[i].elements.length; j++){var input = documentForms[i].elements[j];if(input.type == "text" || input.type == "password" || input.type == null){var text = input.value;input.focus();var event = document.createEvent('TextEvent');event.initTextEvent('textInput', true, true, window, 'a');input.dispatchEvent(event);input.value = text;input.blur();}}
}

此代码基于以下事实:输入其他文本后,Google Chrome就会删除Webkit样式。 仅仅更改输入字段的值是不够的,Chrome需要一个事件。 通过关注每个输入字段(文本,密码),我们可以发送键盘事件(字母“ a”),然后将文本值设置为其先前的状态(自动填充的文本)。 请记住,此代码将在每个浏览器中运行,并将检查网页中的每个输入字段,并根据您的需要进行调整。

删除Chrome自动完成功能的输入背景色?相关推荐

  1. 去掉Chrome自动填充表单浅黄色背景色

    前言 今天玩推时看到Chrome自动填充表单一个安全性问题,瞬间勾起我对其另一个显示问题的不满,忍不住小吐槽一下. 问题 Chrome自动填充表单(记住用户名或密码)时,input会出现黄色的背景.如 ...

  2. Mac 关闭Chrome自动更新功能

    关闭Chrome浏览器,打开终端执行以下命令 cd ~/Library/Google sudo chown root:wheel GoogleSoftwareUpdate 重启Chrome浏览器

  3. c语言自动填表chrome网页,教你设置Chrome浏览器里的自动填表功能

    [IT168 应用]大家在进行网络购物或者一些网站注册时,往往需要填写收货的地址以及信用卡的支付信息,如果每次都要填写这些信息,显然会非常复杂,并且可能因为没有记住而去再次查询确认身份的信息等. 通过 ...

  4. 如何禁用Web表单字段/输入标签上的浏览器自动完成功能?

    如何在主要浏览器中为特定input (或form field )禁用autocomplete ? #1楼 您可以在输入中使用. 例如; <input type=text name="t ...

  5. 利用Chrome浏览器“自动下载”功能窃取Windows登录密码

    本文讲的是利用Chrome浏览器"自动下载"功能窃取Windows登录密码,在过去的十几年中,除了IE以及Edge浏览器之外,其余还没有公开针对SMB认证攻击的方法.这篇文章介绍的 ...

  6. chrome正受到自动软件的控制_谷歌优化Chrome Omnibox自动完成功能 使其更加智能

    为了让 Chrome 用户更方便地导航到自己想要的网址,谷歌正计划对浏览器 Omnibox 中的自动完成功能进行优化,使其变得更加智能.谷歌将全新的自动完成体验称之为"Rich autoco ...

  7. chrome自动退出的原因_Chrome 70将让用户选择退出新的自动登录功能

    chrome自动退出的原因 An upcoming Chrome option allows users to log into Google accounts without logging int ...

  8. Chrome谷歌浏览器私密浏览自动开启功能获批专利

    Chrome谷歌浏览器私密浏览自动开启功能获批专利 谷歌近日被授予一项新的专利:在桌面和移动浏览器中自动启用匿名浏览功能.谷歌这项美国专利号是8935798 B1,专利描述为用户使用浏览器上网,自动阻 ...

  9. chrome关闭自动升级_为什么Chrome的自动完成功能不安全以及如何将其关闭

    chrome关闭自动升级 Chrome has yet to fix a well-known vulnerability first publicized way back in 2013. Chr ...

最新文章

  1. 学习web前端开发要注意什么
  2. 文字在div中垂直居中
  3. oracle java连接配置
  4. 关于架构的优化和设计,架构师必须悟透的事情
  5. 线程的生命周期和状态控制
  6. typescript接口定义
  7. 给 SAP BTP 创建的 Java 应用添加 Custom Event Handler 支持创建功能
  8. 字符串在编号查询中的应用示例及常见问题.sql
  9. 共享单车数据集_共享单车项目数据可视化展示
  10. jsp用户登录验证_Java之使用过滤器进行登录验证
  11. 超准!生活中48条让人匪夷所思的诡秘心理...
  12. sqlplus连接mysql_sqlplus 命令连接数据库
  13. python通过selenium模块模拟自动登录(以QQ空间为例)
  14. 电子邮箱市场盈利模式
  15. 软件测试的六大测试质量标准
  16. The bean sellergoods.FeignClientSpecification could not be registered. A bean with that name has a
  17. 土法炼钢:怎么实现一个简单的B+Tree In-Disk
  18. linux下用u盘安装xp系统安装教程,利用Ubuntu启动U盘安装DOS和WindowsXP
  19. 安装与破解IntelliJ IDEA2017
  20. js全屏和退出全屏代码

热门文章

  1. java中string和stringbuffer
  2. ASP.NET 2.0构建动态导航的Web应用程序(TreeView和Menu )[转载]
  3. 关于线段树or 树状树状 在二维平面搞事情!Orz
  4. Android 应用资源及R文件的位置
  5. 列表、表格与媒体元素
  6. 我想去做机器学习 接下来发一些机器学习实战的算法
  7. BZOJ 3238: [Ahoi2013]差异 [后缀数组 单调栈]
  8. MVC Razor基础
  9. 从SharePoint 2013迁移到SharePoint Online - 评估工具
  10. SQL Server数据库表锁定原理以及如何解除表的锁定