16

When I write in the email box the email, I have no problem and displays perfectly. But when google chrome decides to autofill, the image on the left is removed. http://s9.postimg.org/suz3z56f3/Sem_t_tulo.jpg

I've read some topics about hacking that yellow background, which works, but the image continues to disappear.

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

// html

<input type='email' class='email' placeholder='email'/>

// css

.email{
    background-image: url('http://www.letsgocook.net/sites/default/img/email.png');
    background-repeat: no-repeat;
    padding-left: 35px;
}

http://jsfiddle.net/9AM6X/ > example, but no showing the error because I can't replicate the autofill of chrome in jsfiddle.

user3243925
  • 251
  • 1
  • 4
  • 12
  • 1
    why not try using `input:-webkit-autofill, .email { \* existing .email styles *\ }` – Pete Jan 28 '14 at 10:12
  • 1
    It is not my answer. Still hope it helps http://stackoverflow.com/questions/2920306/google-chrome-form-autofill-and-its-yellow-background [1]: http://stackoverflow.com/questions/2920306/google-chrome-form-autofill-and-its-yellow-background – sree Jan 28 '14 at 10:17
  • 1
    Did you ever manage to find an answer to this? – blueprintchris Nov 22 '16 at 14:41
  • 1
    @blueprintChris yes it is possible with faux elements. – AntonB Jan 10 '17 at 14:33

7 Answers7

8

Puts the image back using keyframes:

@-webkit-keyframes autofill {
    to {
        background-image:url(images/your-input-bg-image.svg);
    }
}

input:-webkit-autofill {
    -webkit-animation-name: autofill;
    -webkit-animation-fill-mode: both;
}

Kudos to @Steve for his answer to Removing input background colour for Chrome autocomplete?

wkille
  • 435
  • 5
  • 10
6

I'm posting a solution here, essentially as a hack / workaround for the problem described.

Using extra elements we can place the icon on the input element.

Preview: http://output.jsbin.com/necigedago

Working Example:

enter image description here

CSS

.control {
    position: relative;
}

.email {
    padding-left: 35px;
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 16px;
}

.email ~ .input-icon {
    background-image: url('http://www.letsgocook.net/sites/default/img/email.png');
    background-repeat: no-repeat;
    background-size: 100%;
    background-position: center center;
    width: 22px;
    height: 14px;
    position: absolute;
    left: 8px;
    bottom: 0;
    top: 0;
    margin: auto;
}

HTML

  <p class='control'>
    <input type='email' class='email' placeholder='email'/>
    <span class='input-icon'></span>
  </p>
AntonB
  • 2,325
  • 1
  • 25
  • 36
3

It is very inconvenient practice to use background images for textboxes. you can change your HTML markup

html

<div class='icon'></div>
<input type='email' class='email' placeholder='email'/>

css

.email {
    border:1px solid black;
    padding-left: 5px;
    float:left;
    border-left:none;
    outline:none ;
    margin-left:-3px
}

.icon {
    background-image: url('http://www.letsgocook.net/sites/default/img/email.png');
    background-repeat: no-repeat;
    background-position:center center ;
    float:left;
    width:30px;
    height:18px;
    margin-top:2px;
    border:1px solid black;
    border-right:none
}

I have updated the code: jsFiddle

Fabian Schultz
  • 14,323
  • 4
  • 44
  • 51
Taron Mehrabyan
  • 2,079
  • 2
  • 18
  • 22
2

Only option is to remove the padding where the background image would have been in webkit but you can style as such:

/* CHROME ISSUE W/ YELLOW BG */
input:-webkit-autofill#username,
input:-webkit-autofill#usernameId_new,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
-webkit-text-fill-color: #646464 !important;
-webkit-box-shadow: 0 0 0px 1000px #fff inset;
-webkit-padding-start: 8px !important;
}

The image will still work for IE, FF, etc... but for chrome will overide.

Best-

2

Use animate to solve this matter is the most useful way!

kudos to @wkille for his answer: https://stackoverflow.com/a/51874418/11720087

You can set a animation like this:

@keyframes clearAutofill {
  to { background: 'Your-code'; }
  /* e.g background: url('./img/example.png') 0 0 no-repeat #fff; */
}

input:-webkit-autofill {
  animation: clearAutofill forwards;
  /* 'animation-fill-mode: forwards' can keep the style you set. */
}
Choumode
  • 21
  • 2
1

I found a better solution to this.

For new Chrome versions, you can just put autocomplete="new-password" in your password field and that's it. I've checked it, works fine.

Grasper
  • 1,264
  • 10
  • 22
1

You just need to add autocomplete="off" to your input field and this will solved the issue. I tried it and it works.

Manuel Abascal
  • 3,169
  • 3
  • 21
  • 30