使用HTML / CSS覆盖浏览器表单填写和输入突出显示

我有2种基本表单-登录和注册,都在同一页面上。现在,我可以自动填写表单登录了,但是注册表单也会自动填写,我不喜欢它。


此外,表单样式的背景为黄色,我无法覆盖它,也不想使用内联CSS来实现。我该怎么办才能使它们停止变为黄色和(可能)自动填充?提前致谢!


精慕HU
浏览 594回答 3
3回答

POPMUISE

对于自动完成,可以使用:<form autocomplete="off">关于着色问题:从屏幕截图中,我可以看到该webkit生成以下样式:input:-webkit-autofill {&nbsp; &nbsp; background-color: #FAFFBD !important;}1)由于#id样式比.class样式更为重要,因此可以使用以下方法:#inputId:-webkit-autofill {&nbsp; &nbsp; background-color: white !important;}2)如果不起作用,您可以尝试以编程方式通过javascript设置样式$("input[type='text']").bind('focus', function() {&nbsp; &nbsp;$(this).css('background-color', 'white');});3)如果那行不通,那就注定了:-):这不会隐藏黄色,但是会使文本再次可读。input:-webkit-autofill {&nbsp; &nbsp; &nbsp; &nbsp; color: #2a2a2a !important;&nbsp;&nbsp; &nbsp; }4)CSS / JavaScript解决方案:CSS:input:focus {&nbsp; &nbsp; background-position: 0 0;}并且以下javascript必须在加载时运行:function loadPage(){&nbsp; &nbsp; if (document.login)//if the form login exists, focus:&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; document.login.name.focus();//the username input&nbsp; &nbsp; &nbsp; &nbsp; document.login.pass.focus();//the password input&nbsp; &nbsp; &nbsp; &nbsp; document.login.login.focus();//the login button (submitbutton)&nbsp; &nbsp; }}例如:<body onload="loadPage();">祝好运 :-)5)如果上述任何一项均未尝试删除输入元素,将其克隆,然后将克隆的元素放回到页面上(在Safari 6.0.3上可用):<script>function loadPage(){&nbsp; &nbsp; var e = document.getElementById('id_email');&nbsp; &nbsp; var ep = e.parentNode;&nbsp; &nbsp; ep.removeChild(e);&nbsp; &nbsp; var e2 = e.cloneNode();&nbsp; &nbsp; ep.appendChild(e2);&nbsp; &nbsp; var p = document.getElementById('id_password');&nbsp; &nbsp; var pp = p.parentNode;&nbsp; &nbsp; pp.removeChild(p);&nbsp; &nbsp; var p2 = p.cloneNode();&nbsp; &nbsp; pp.appendChild(p2);}document.body.onload = loadPage;</script>6)从这里:if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) {&nbsp; &nbsp; $(window).load(function(){&nbsp; &nbsp; &nbsp; &nbsp; $('input:-webkit-autofill').each(function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var text = $(this).val();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var name = $(this).attr('name');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(this).after(this.outerHTML).remove();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('input[name=' + name + ']').val(text);&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; });}

慕丝7291255

使用“强烈”的内部阴影来欺骗它:input:-webkit-autofill {&nbsp; &nbsp; -webkit-box-shadow:0 0 0 50px white inset; /* Change the color to your own background color */&nbsp; &nbsp; -webkit-text-fill-color: #333;}input:-webkit-autofill:focus {&nbsp; &nbsp; -webkit-box-shadow: 0 0 0 50px white inset;/*your box-shadow*/&nbsp; &nbsp; -webkit-text-fill-color: #333;}&nbsp;

幕布斯6054654

经过2个小时的搜索,看来Google Chrome浏览器仍然可以覆盖黄色,但是我找到了解决方法。它也将适用于悬停,聚焦等。您所要做的就是添加!important它。input:-webkit-autofill,input:-webkit-autofill:hover,input:-webkit-autofill:focus,input:-webkit-autofill:active {&nbsp; &nbsp; -webkit-box-shadow: 0 0 0px 1000px white inset !important;}这将完全消除输入字段中的黄色
打开App,查看更多内容
随时随地看视频慕课网APP