出现的问题
在做一个表单时使用chrome浏览器输入表单内容,在第二次测试的时候出现了自动填充的选项,选择后发现输入框的样式不再是手动设置的样式
原手动填充效果如下:
选择自动填充后的样式:
此时观察input框样式:
发现了autofill的样式内容,这在代码里是没有写的,chrome浏览器自动填充就会触发这一现象,在网上看了这个的解释
他告诉我们,只要重定义这个样式就可以了
从网上找了一个方法解决这个问题
<style>
#name {
background-color: #000;
color: white;
}
#name:-webkit-autofill {
box-shadow: 0 0 0 1000px #000 inset;
-webkit-text-fill-color: white;
}
#name:autofill {
box-shadow: 0 0 0 1000px #000 inset;
-webkit-text-fill-color: white;
}
</style>
<body>
<fieldset>
<legend>
提交表单
</legend>
<form>
<label for="name">姓名:</label>
<input type="text" id="name" value="" placeholder="请输入名称!" /><br/>
<label for="pwd">密码:</label>
<input type="password" id="pwd" value="" placeholder="请输入密码!" /><br />
<input type="submit" value="提交">
</form>
</fieldset>
</body>