How to prevent Chrome from changing font when autofilling username/password?

前端 未结 5 1915
情书的邮戳
情书的邮戳 2020-11-30 04:50

I have a login form with username and password inputs. In Chrome on Windows (doesn\'t happen in other browsers or on a Mac), when hovering over a saved username from the Chr

相关标签:
5条回答
  • 2020-11-30 05:03

    This seems to be a recent change in Chrome: Issue 953689: Previously entered form values overrides styling when moused over. As far as I’ve seen this happens both on macOS and Windows, anywhere autofill is presented to the end user. Apparently this has intentionally been done to fix a security issue with the previous implementation – Issue 916838: Security: Two autocomplete flaws together allow sites to invisibly read credit card numbers after a single keypress

    There doesn’t seem to be a way to override those new styles at the moment – if the change in styles is really too obnoxious, you can either disable autofill (Disabling Chrome Autofill) or set your field’s font styles (font-family, font-weight, font-style, font-size to match that of Chrome’s autofill suggestions – as suggested here: https://stackoverflow.com/a/56997845/1798491)

    0 讨论(0)
  • 2020-11-30 05:11

    How to change Chrome autocomplete styles on input:

    input {
    ...
    font-family: $body-font;
    font-size: 1rem;
    font-weight: bold;
    color: #000;
    background-color: #fff;
      
    // Background color
    &:-webkit-autofill {
      -webkit-box-shadow: 0 0 0 1000px #fff inset;
    }
      
    // Font styles
    &:-webkit-autofill::first-line {
      font-family: $body-font;
      font-size: 1rem;
      font-weight: bold;
      // color: green;
    }
    

    }

    0 讨论(0)
  • 2020-11-30 05:14

    I don't run on windows but have you tried targeting the label and form as well? Re: css specificity. Then try web-kit auto-fills on all

    0 讨论(0)
  • 2020-11-30 05:20

    As of now it seems that there's no way to change this in Chrome. I'd definitely call it a bug.

    However, a decent workaround is to set the font-family for all autofill-able inputs or inputs within forms that have autofill abilities to this:

    font-family: -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Ubuntu, Arial, sans-serif;

    This is a great cross-browser, cross-platform solution because it just takes whatever your system font is, which is exactly what Chrome seems to be doing for it's autofill font.

    It also ensures that your forms are going to have readable fonts on whatever OS your user is using.

    0 讨论(0)
  • 2020-11-30 05:26

    try this!

          &:-webkit-autofill::first-line,
          &:-webkit-autofill,
          &:-webkit-autofill:hover,
          &:-webkit-autofill:focus,
          &:-webkit-autofill:active {
            font-family: Times, "Times New Roman", serif !important;
          }
    

    you might only need this though

         &:-webkit-autofill::first-line
    

    the others are just incase

    0 讨论(0)
提交回复
热议问题