我有一个表单,在输入中我在左边有一个图标,使用背景和左边的位置。
该设计运行完美,但我在两个输入中看到自动出现了我的电子邮件和密码,因此我的背景消失了。
我尝试过使用 input:-webkit-autofill、input:-webkit-autofill、:focus 和 input autocomplete="off"但没有任何改变。
所以我只在第一次进入页面时遇到问题,但如果我删除自动填充文本,我会正确看到背景。
那么,无论是否有自动填充,我怎样才能让“背景”图像图标始终出现?
这是 haml:
= f.email_field :email, autofocus: true, class: "email", placeholder: "Email", autocomplete: "off"
= f.password_field :password, autocomplete: "off", class: "password", placeholder: "#{t'common.password'}"
还有 CSS:
input.email {background: $crema url("/assets/profile_mail.png") left no-repeat; background-size: 40px 40px;}
input.password {background: $crema url("/assets/profile_password.png") left no-repeat; background-size: 40px 40px;}
input.email:focus {background: $crema url("/assets/profile_mail.png") left no-repeat; background-size: 40px 40px;}
input.password:focus {background: $crema url("/assets/profile_password.png") left no-repeat; background-size: 40px 40px;}
input.email:-webkit-autofill:focus {background: $crema url("/assets/profile_mail.png") left no-repeat; background-size: 40px 40px;}
input.password:-webkit-autofill:focus {background: $crema url("/assets/profile_password.png") left no-repeat; background-size: 40px 40px;}
最佳答案
试试这个:
<% form_for :form_name, @form_name, :html => {:autocomplete => "off"} do |f|%>
...
<% end %>
关于CSS 和表单 autofil 背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25827737/