Please enable Javascript to view the contents

input自动填充时背景色改变问题

 ·  ☕ 1 分钟  ·  ✍️ YSL

input 输入框 在自动填充时,背景颜色问题]

问题:

自动填充前:

img

自动填充后:

img

可以看出,自动填充后,input背景颜色变成了白色,

解决办法:
  1. 纯色阴影覆盖底色
1
2
3
4
     input:-webkit-autofill {
         box-shadow: 0 0 0 1000px #333333 inset;
         -webkit-text-fill-color: #fff;
     }

再看看,自动填充后的效果:

img

注意: 这个方法有个问题,就是input 输入框,不能有 圆角(border-radius),而且只适用于纯色背景框。

img

可以看到,两边有明显的白色

  1. 设置透明:
1
2
3
4
5
input:-internal-autofill-previewed,
input:-internal-autofill-selected {
    -webkit-text-fill-color: #807c7c;
    transition: background-color 5000s ease-out 0.5s;
}

效果:

img

  1. 利用动画延迟

复制代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus, 
input:-webkit-autofill:active {
    transition-delay: 99999s;
    transition: color 99999s ease-out, background-color 99999s ease-out;
    -webkit-transition-delay: 99999s;
    -webkit-transition: color 99999s ease-out, background-color 99999s ease-out;
    -webkit-text-fill-color: #807c7c;
}

复制代码

效果:

img