删除 Chrome 自动完成功能的输入背景颜色?

Removing input background colour for Chrome autocomplete?

提问人:DisgruntledGoat 提问时间:5/6/2010 更新时间:9/23/2023 访问量:811953

问:

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

我正在做的设计是在深色背景上使用浅色文本,所以这确实弄乱了表单的外观 - 我有鲜明的黄色框和几乎看不见的白色文本。一旦场聚焦,场就会恢复正常。

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

自动完成 输入 google-chrome

评论


答:

63赞 Mohamed Mansour 5/7/2010 #1

这是由于此着色行为来自 WebKit 以来的设计。它允许用户了解数据已被预填充。错误 1334

您可以通过执行以下操作来关闭自动完成功能(或在特定的窗体控件上:

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

或者,您可以通过以下方式更改自动填充的颜色:

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

请注意,正在跟踪一个错误以使其再次工作:http://code.google.com/p/chromium/issues/detail?id=46543

这是 WebKit 的行为。

评论

28赞 DisgruntledGoat 5/29/2010
谢谢,但webkit CSS规则不起作用。用户代理样式表总是否决背景颜色,即使它 (a) 设置为和 (b) 以 ID 为目标以获得更高的特异性。看起来Chrome总是会覆盖它。删除自动完成似乎确实有效,但这真的不是我想做的。!important
1赞 Mohamed Mansour 5/30/2010
有些人有同样的问题,你检查过错误帖子吗?code.google.com/p/chromium/issues/detail?id=1334
8赞 João 4/4/2012
Chrome 会阻止任何 CSS 尝试覆盖该黄色。设置肯定会引发可访问性问题。为什么这个答案被标记为正确?autocomplete="off"
2赞 Tim Scollick 6/5/2015
这是一个很好的解决方案,但如果你使用的是 React,它会抱怨自动完成是一个未知的 DOM 属性。因此,它实际上是自动完成的(注意驼峰大小写)。
3赞 Paullo 3/17/2017
关闭自动完成是一个黑客,而不是解决方案
9赞 Benjamin 11/24/2010 #2

如果你想保持自动完成功能不变,你可以使用一些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);
    });
});}

评论

0赞 João 4/4/2012
这似乎是最好的解决方案,尽管它阻止了 Kicksend 的邮件检查。关于如何解决这个问题的任何想法?
0赞 vanval 9/27/2014
这不是一个好的解决方案,因为谷歌浏览器的密码自动完成停止工作。也就是说,最初您填写名称,Google Chrome会自动填写密码。但是,一旦上述javascript执行,名称将被删除并重新设置,并且自动填充的密码将丢失
7赞 Daniel Fairweather 2/18/2012 #3

我开发了另一个使用没有 JQuery 的 JavaScript 的解决方案。如果您觉得这有用或决定重新发布我的解决方案,我只要求您包括我的名字。享受。——丹尼尔·费尔韦瑟

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”),然后将文本值设置为其先前状态(自动填充文本)。请记住,此代码将在每个浏览器中运行,并将检查网页中的每个输入字段,并根据您的需要进行相应调整。

评论

0赞 Dustin Silk 4/30/2015
好吧,它在很大程度上起作用了。不幸的是,它清除了我的密码。试图让它先保存密码并在 for 循环后重置它,但 chrome 似乎遇到了一些问题。嗯
46赞 Tamás Pap 12/13/2012 #4

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

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

评论

3赞 davidkonrad 8/19/2016
这是实际有效的解决方案,我们不想只跳过黄色背景几次,因为接受的答案会导致。
1635赞 Fareed Alnamrouti 1/8/2013 #5

您可以更改输入框样式以及框内的文本样式:input

在这里,您可以使用任何颜色,例如 , , .white#DDDrgba(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 的“模糊半径”将完美地覆盖它。

编辑 2023:要同时具有透明度和更改背景颜色的能力:

input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active{
    -webkit-background-clip: text;
    -webkit-text-fill-color: #ffffff;
    transition: background-color 5000s ease-in-out 0s;
    box-shadow: inset 0 0 20px 20px #23232329;
}

请注意,此处的转换在最近的 Chrome 浏览器中没有任何作用,它只是旧版本 Chrome 的后备解决方案。

评论

8赞 Andy 4/12/2019
现在,在 Chrome 中,用户代理样式表显示和伪类,而不是......然而,神秘的是,它仍然有效。我个人不需要.:-internal-autofill-previewed:-internal-autofill-selected-webkit-autofill-webkit-autofill!important
0赞 Antoine 5/14/2020
我不需要悬停/对焦/主动伪选择器
0赞 Muhammad Ali 8/30/2020
这会使焦点的高光变暗,并使其变得坚实而细。有解决方案吗?
1赞 beano 12/31/2020
如果使用半透明背景并希望将其完全删除,请使用。-webkit-box-shadow: none
2赞 Cyman 4/7/2023
只是想提一下,文本的解决方案有效,只是管道颜色保持不变,除非您声明caret-color: yellow
4赞 ed1nh0 10/24/2013 #6

我放弃了!

由于无法通过自动完成功能更改输入的颜色,因此我决定使用 webkit 浏览器的 jQuery 禁用所有这些颜色。喜欢这个:

if (/webkit/.test(navigator.userAgent.toLowerCase())) {
    $('[autocomplete="on"]').each(function() {
        $(this).attr('autocomplete', 'off');
    });
}
4赞 i_a 4/26/2014 #7

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

于是我问自己,“Chrome 如何确定在给定页面上应该自动填充哪些内容?

“它是否查找输入ID,输入名称?表格 ID?形成行动?

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

1) 将密码输入放在文本输入之前。2)给他们相同的姓名和ID...或者根本没有姓名和身份证。

页面加载后,使用 javascript,您可以动态更改页面上输入的顺序,或者动态地为它们提供名称和 ID ...

Chrome 不知道是什么击中了它......自动完成功能坏了!

疯狂的黑客,我知道。但它对我有用。

铬 34.0.1847.116, OSX 10.7.5

12赞 Linghua Jin 6/18/2014 #8

除此之外:

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

另一方面,当您单击输入时,黄色将返回。 对于焦点,如果你使用的是 bootstrap,第二部分是用于边框突出显示 0 0 8px rgba(82, 168, 236, 0.6);

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

5赞 jedmao 3/14/2015 #9

对于使用 Compass 的用户:

@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);
            }
        }
    }
}
417赞 Nathan White 3/30/2015 #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;
}

评论

13赞 gfpacheco 12/29/2015
太棒了,我还需要一个透明的背景。PS:别忘了 for 文本颜色。-webkit-text-fill-color: yellow !important;
0赞 xyhhx 2/20/2016
当输入被隐藏/显示时,这仍将显示自动填充背景。小提琴 - 看看吧display
37赞 Shaggy 4/27/2016
与其设置高得离谱,不如设置这样可以进一步减少颜色发生任何变化的可能性。transition-durationtransition-delay
6赞 TetraDev 7/2/2016
很棒的解决方案....但为什么这有效呢?为什么设置不起作用?Chrome需要解决这个问题!background-color
5赞 RienNeVaPlu͢s 2/14/2019
用途:延迟所有样式更改input:-webkit-autofill { transition: all 0s 50000s; }
24赞 Jack Russell 6/12/2015 #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;
}

评论

0赞 Matteo Tassinari 7/20/2016
我已经设置了一个图像作为输入字段的背景,这个解决方案去除了黄色阴影,但背景图像仍然被隐藏
0赞 sdlins 6/6/2020
这是 Chrome 83 中唯一适合我的。得票最多的一个是工作到Chrome 82。
85赞 Gísli Freyr Svavarsson 9/10/2015 #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;
}

评论

8赞 Matteo Tassinari 7/20/2016
我已经设置了一个图像作为输入字段的背景,这个解决方案去除了黄色阴影,但背景图像仍然被隐藏
0赞 Yoann 8/24/2016
迄今为止最好的解决方案,与现有验证配合得很好box-shadow
0赞 naanace 6/14/2018
Chrome 表示 is not valide exprssion。我当时使用了代码,然后"color 9999s ease-out, background-color 9999s ease-out";-webkit-transition: background-color 9999s ease-out;-webkit-text-fill-color: #fff !important;
0赞 Paul Razvan Berg 12/2/2019
@Yoann它究竟是如何与您现有的验证一起工作的?就我而言,由于这个 css 规则,我的自定义红框阴影(表示输入错误)被延迟,使用户认为最近的输入是无效的,而实际上它是好的。box-shadow
16赞 Surender Lohia 9/24/2015 #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;
}

评论

0赞 Lindsay-Needs-Sleep 12/24/2020
我最喜欢这个,因为这意味着我没有专门设置我的背景颜色或文本颜色。(适用于我的组件,它与各种不同的颜色一起使用。我将延迟从 0 秒更改为 5000 秒,以额外增加 5000 秒作为我的背景颜色和文本颜色。
24赞 Patrick Fisher 10/24/2015 #14

SASS公司

input:-webkit-autofill

  &,
  &:hover,
  &:focus,
  &:active
    transition-delay: 9999s
    transition-property: background-color, color

评论

1赞 CleoR 12/23/2015
这实际上对我有用,因为接受的答案闪烁着淡黄色。
27赞 Francisco Costa 12/11/2015 #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;
}

评论

1赞 Geuis 5/12/2016
对于好奇的人来说,背景色没有效果。-webkit-box-shadow 是覆盖 Chrome 中黄色背景的巧妙位
21赞 Alex 3/22/2016 #16

我遇到了一个问题,我不能使用 box-shadow,因为我需要输入字段是透明的。这有点黑客,但纯粹是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;
}

评论

0赞 vivekkupadhyay 4/14/2016
截至目前在最新的 Chrome 50.x.x 中,它运行良好。多谢!
6赞 Shaggy 4/27/2016
与其设置高得离谱,不如设置这样可以进一步减少颜色发生任何变化的可能性。transition-durationtransition-delay
0赞 Alex 5/13/2016
@Shaggy谢谢,我只是把它切换到延迟。好多了。
337赞 Steve 5/25/2016 #17

之前添加箱形阴影的解决方案适用于需要纯色背景的人。添加过渡的另一种解决方案有效,但必须设置持续时间/延迟将意味着它可能会在某个时候再次显示。

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

@-webkit-keyframes autofill {
    0%,100% {
        color: #666;
        background: transparent;
    }
}

input:-webkit-autofill {
    -webkit-animation-delay: 1s; /* Safari support - any positive time runs instantly */
    -webkit-animation-name: autofill;
    -webkit-animation-fill-mode: both;
}

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

评论

5赞 skwidbreth 12/20/2019
我发现这比公认的答案要好......box-shadow 方法很聪明并且确实有效,但是当用户选择要自动填充的值时,默认颜色会在输入字段中短暂闪烁,如果您的输入具有深色背景,这可能会很麻烦。此解决方案没有此类问题。干杯!
3赞 Marc 1/22/2020
这适用于 Vuetify 2,特别是如果您将color: inherit
11赞 sanjuro 3/3/2021
这曾经对我有用,但在最新的 chrome(88) 中不是。有什么想法吗?和更新的解决方案?
5赞 Nicolas Arias 10/15/2016 #18

如果您想阻止谷歌浏览器的自动填充,我有一个解决方案,但它有点“砍刀”,只需删除谷歌浏览器添加到这些输入字段的类,并将值设置为“”如果您不需要显示加载后存储数据。

$(document).ready(function () {
    setTimeout(function () {
        var data = $("input:-webkit-autofill");

        data.each(function (i, obj) {
            $(obj).removeClass("input:-webkit-autofill");
            obj.value = "";
        });
    }, 1);          
});
26赞 don 11/3/2016 #19

经过 2 小时的搜索,谷歌似乎仍然以某种方式覆盖了黄色,但我解决了它。没错。它也适用于悬停、聚焦等。您所要做的就是向其添加 !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;
}

这将从输入字段中完全删除黄色

7赞 AmerllicA 10/19/2017 #20

Google Chrome 用户代理阻止了开发人员的,因此对于更改 UI 必须使用另一个属性,如下所示:CSSautofill

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*/
}

评论

0赞 Oliver 7/23/2020
该属性不再需要前缀 with,当然,在可能的情况下,将 this 的大小设置为输入高度的一半(而不是 )会更高性能。但除此之外,不幸的是,这是解决问题的最佳方法box-shadow-webkit-1000px
10赞 2ne 12/18/2017 #21

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

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

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

请参见 CODEPEN

评论

0赞 manuel-84 6/28/2020
好的,但与许多其他解决方案一样,这将不允许我拥有透明的背景
5赞 arczi 12/31/2017 #22

这对我有用:

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

评论

1赞 David 9/2/2021
background-clip: text;在 Chrome 中工作
12赞 Waqas Anwar 2/9/2018 #23

这将适用于正常、悬停、焦点和活动状态下的输入、文本区域和选择。

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 0 1000px white inset !important;
}

这是上述解决方案的 SCSS 版本,适用于使用 SASS/SCSS 的用户。

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

评论

0赞 shrekuu 7/6/2023
你给这个问题带来了乐趣。♪(^∇^*)
20赞 StefansArya 6/25/2018 #24

添加一小时的延迟将暂停对输入元素的任何 css 更改。
这比添加过渡动画或内部阴影更好。

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

评论

0赞 Reed 11/12/2020
刚刚浏览了这个线程并用过渡延迟对所有答案投了赞成票,它工作得很好,如果将代码传递给不知道你为什么要把它放在那里的其他人,它很容易理解。
6赞 Ali Bagheri 2/5/2019 #25

这适用于我删除字段的黄色背景:

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
input:-webkit-autofill:valid,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
    -webkit-transition-delay: 99999s;
    -webkit-text-fill-color:#D7D8CE;
}
4赞 Parveen Chauhan 6/17/2019 #26

我们可以使用伪选择器来定位这些字段,并按照我们认为合适的方式设置它们的样式。默认样式仅影响背景颜色,但大多数其他属性都适用于此处,例如边框和字体大小。我们甚至可以更改文本的颜色,该颜色包含在下面的代码片段中。-webkit-autofill-webkit-text-fill-color

/* Change Autocomplete styles in Chrome*/
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
    border: 1px solid green;
    -webkit-text-fill-color: green;
    -webkit-box-shadow: 0 0 0px 1000px #000 inset;
    transition: background-color 5000s ease-in-out 0s;
}

评论

1赞 freek van der wand 12/22/2021
你提到了font-size:我如何实际更改font-size?添加不起作用font-size: 24px
164赞 manuel-84 6/28/2020 #27

要在不使用时间延迟的情况下拥有透明的背景(尤其是在现代 Web 应用程序中需要,人们可以暂时停止使用它并希望界面的行为可预测),请使用以下命令:

input:-webkit-autofill { 
    -webkit-background-clip: text;
}

body {
  background: lightblue;
}

input {
  background: transparent;
}

input.no-autofill-bkg:-webkit-autofill {
  -webkit-background-clip: text;
}
<input type="text" name="email" />
<input type="text" name="email" class="no-autofill-bkg" />

正在处理: Chrome 83 / 84.0.4147.89, Edge 84.0.522.44

评论

0赞 Ricky Boyce 7/30/2020
不幸的是,这不适用于带有集合的输入background-color
0赞 KABA 8/27/2020
谢谢。另外,它会影响下面评论中的 Bootstrap 风格吗?@manuel-84 stackoverflow.com/questions/21401766/...
0赞 manuel-84 8/29/2020
@KABA是的,当然它会覆盖 webkit 上的 background-clip 属性,它仍然是 CSS 代码,所以每个人都必须研究对他的代码库的影响
4赞 Black 3/5/2021
要更改颜色,请添加-webkit-text-fill-color: white !important;
2赞 Redemption Okoro 7/20/2023
对我来说很完美~~ 2023 年 7 月
5赞 tahmasib 4/3/2021 #28

可以更改此框的颜色,例如已接受的答案。

但是,如果要使背景透明,则此方法没有用。但是,有一种方法(或者更确切地说是解决方法)可以使其透明,如下所示:

input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active  {
    transition: background-color 5000s;
    -webkit-text-fill-color: #fff !important;
}

这基本上等同于透明背景。

评论

1赞 ChrisAdmin 10/21/2021
这是唯一一个在现代 Chrome 中工作的人
93赞 Hannes Schneidermayer 9/28/2021 #29

2023 年更新

在最新更新后工作:

input:-webkit-autofill,
input:-webkit-autofill:focus {
    transition: background-color 600000s 0s, color 600000s 0s;
}
input[data-autocompleted] {
    background-color: transparent !important;
}

评论

1赞 Brian Poole 9/27/2022
如果无法使它正常工作,请确保没有另一个过渡集覆盖输入上的此过渡。
0赞 AzizStark 8/20/2023
浏览器对此的支持如何?
1赞 Hannes Schneidermayer 8/29/2023
@AzizStark caniuse.com/css-transitions 安全使用
8赞 Marghen 1/31/2023 #30

2023 - 透明背景

对于深色背景上的透明输入背景(浅色文本):

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

评论

0赞 Getsumi3 6/5/2023
我喜欢这个答案。但我会用transition-webkit-background-clip: text;;
0赞 Marghen 6/6/2023
谢谢你@Getsumi3,我用你的贡献更新了答案。我将过渡部分留给较旧的浏览器作为后备。
0赞 XXIV 10/9/2023
在IOS上不起作用
0赞 Marghen 10/10/2023
你是什么意思?它在我的项目和 CodePen codepen.io/Marghen23/pen/JjwxByM 上运行良好