Chrome's autofill hiding text input's background image

青春壹個敷衍的年華 提交于 2021-01-26 11:01:20

问题


After successfuly disabling the autofill's yellowish background-color, I stumbled upon another feature.

Each of my input elements have a background image, and every time I focus on a text input, the browser suggests values I used before in a drop down list.

After I pick a value, the autofill covers my entire background and hides the image.

Here's my html and css (elaborated in JSfiddle):

<section class="formContainer">
    <img class="sesameLogo" src="~/Content/Images/Site/sesamelogo.png" />
    <form id="signUpForm" class="pageForm">
        <input type="text" name="decoy" class="decoy"/>
        <input type="password" name="decoy" class="decoy" />
        <input type="text" placeholder="Full Name" name="FullName" id="fullName" />
        <input type="text" placeholder="Email" name="email" id="email" />
        <input type="password" placeholder="Password" name="password" id="password" />
        <input type="password" placeholder="Confirm Password" name="confirmPassword" id="secPassword" />
        <section id="actionBtnsCont">
            <button id="btnSignUp" class="mainBtn" type="button">Sign Up</button>
            <label class="genContextLbl">or</label>
            <button id="btnSignIn" class="genBtn" type="button">Sign In</button>
        </section>
    </form>
</section>

https://jsfiddle.net/65wkgqs0/


回答1:


What you need is:

move background image from <input> element

HTML

<div class="email-wrapper">
  <input type="text" placeholder="Email" name="email" id="email" />
</div>

CSS

.email-wrapper {
  display: inline-block;
  background: url(https://www.apec-econ.ca/system/style/images/icon-small-person.png) no-repeat scroll 4px 9px;
}

and postpone changing of background-color when autofill

CSS

input:-webkit-autofill {
  transition: background-color 5000s ease-in-out 0s;
}

Updated your fiddle: https://jsfiddle.net/65wkgqs0/6/



来源:https://stackoverflow.com/questions/34577305/chromes-autofill-hiding-text-inputs-background-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!