Removing input background colour for Chrome autocomplete?

前端 未结 30 2633
失恋的感觉
失恋的感觉 2020-11-22 04:02

On a form I\'m working on, Chrome is auto-filling the email and password fields. This is fine, however, Chrome changes the background colour to a pale yellow colour.

30条回答
  •  野的像风
    2020-11-22 04:22

    The previous solutions of adding a box-shadow works well for people who need a solid colour background. The other solution of adding a transition works, but having to set a duration/delay will mean that at some point it may show again.

    My solution is to use keyframes instead, that way it will always show the colours of your choosing.

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

    Example Codepen: https://codepen.io/-Steve-/pen/dwgxPB

提交回复
热议问题