4

When a form is filled out for a 2nd time and the browser recognises the details it adds a light-blue background to the form input elements on a site I'm building (which currently have the background set as transparent to show the dark blue background of the parent section). Image attached.

Is there a way to prevent this from happening?

It doesn't do it the first time of filling the form in, only if you input the details a second time after submission.

In the attached image I've left the fourth (bottom-right) field blank so you can see how it should look.

Thanks

enter image description here

pjk_ok
  • 618
  • 7
  • 35
  • 90

4 Answers4

1

I would try this:

input:-webkit-autofill {
        //The following works as the text color for the autofill 
        -webkit-text-fill-color: (the text color you want);
        //The following works as a background for the autofill 
        -webkit-box-shadow: 0 0 0px 1000px (here I would add the blue bg color you are using) inset; 

   }
Badr
  • 64
  • 6
1

Why not just override the box-shadow of the input autofill property as shown in this other SO thread like this:

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

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

I tried it on a dummy html form just now and the above (even without the text-fill-color property defined) seems to work fine in removing the blue background.

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
0

1. You can just disable autocomplete in form at all or in some of input fields you want:

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

or

<input type="text" autocomplete="off" />

2. Try to overwrite autofill by own CSS rules

@-webkit-keyframes autofill {
  to {
    color: inherit;
    background: transparent;
  }
}

input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill
{
  -webkit-animation-name: autofill;
  -webkit-animation-fill-mode: both;
}
FlameStorm
  • 944
  • 15
  • 20
-1

You can use the pseudo selector :focus on your input like this to remove the blue outline input:focus { outline: none; }

coding4you
  • 9
  • 1
  • 3
  • This isn't what I want. It's the light-blue background colour on the input elements I want to remove. Also you should never have `outline:none` on your focus property on forms - it creates accessibility issues. You should always have `outline: transparent`. – pjk_ok Oct 14 '19 at 12:43