19

I'm designing a web application and the general style involves white text on a dark background.

This style includes using a custom (dark) image for the username and password fields, with white text.

If users log in using google chrome and choose to save their login details for the form, on the next visit the username and password fields appear as pale yellow with white text, making it nearly impossible to read. This looks really bad.

How would I go about overriding this style, preventing google chrome from changing the background of the saved username and password fields.

<style type="text/css">
  input {
    border: none;
    background: url('darkinput.png');
    color: #fff;
  }
</style>

<input type="text" name="email" id="text" /> 
<input type="password" name="password" id="text" />

EDIT: Currently (google-chrome v11.0.696.57) the user agent stylesheets contain !important overrides to set both of the following:

input:-webkit-autofill{
  background-color: rgb(250, 255, 189) !important;
  background-image: none !important;
}

There is an issue report for this at the url below, and I encourage everyone who reads this to vote it up:

http://code.google.com/p/chromium/issues/detail?id=46543

Knautiluz
  • 354
  • 3
  • 14
Matthew
  • 6,351
  • 8
  • 40
  • 53
  • 1
    Using the box-shadow approach works, however this doesn't solve the problem of font color - example is black shadow, white font. – Marco Moretti Jul 12 '19 at 04:57

4 Answers4

11

Just setting a shadow will fix that:

input:-webkit-autofill { 
  -webkit-box-shadow:200px 200px 100px white inset; 
  box-shadow:200px 200px 100px white inset; 
}
n1kkou
  • 3,096
  • 2
  • 21
  • 32
8

To fully disable auto complete (and therefore removing the style issue) you can try this:

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

However another possibility would be to use jquery to remove the style after the page load.

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);
    });
});}
Creativehavoc
  • 441
  • 3
  • 8
2

To reset the styles:

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

this worked for me.

mezod
  • 2,313
  • 3
  • 21
  • 31
1

Please override the default css, which is

input:-webkit-autofill {
  background-color: #FAFFBD !important;
  background-image:none !important;
  color: #000000 !important;
}
Wolfgang Kuehn
  • 12,206
  • 2
  • 33
  • 46
  • 3
    This works to make the text readable. Unfortunately it appears to be impossible to set the background-color or background-image (even using !important) because the user agent stylesheet for chrome has the background-color and background-image already set using !important. – Matthew Jun 08 '11 at 20:51
  • Matthew is right, using the snippet of my answer solves this without needing to use !important. I am overriding a different property but the final result is what we expect. A white bg! – mezod Nov 17 '15 at 18:14