【发布时间】:2023-03-16 06:14:02
【问题描述】:
我已经设法使用以下代码将自动填充输入字段的背景颜色从黄色更改为白色:
input.login:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
但是,仅通过添加color: #999; 将字体颜色更改为灰色是行不通的。我该如何解决这个问题?非常感谢!
【问题讨论】:
我已经设法使用以下代码将自动填充输入字段的背景颜色从黄色更改为白色:
input.login:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
但是,仅通过添加color: #999; 将字体颜色更改为灰色是行不通的。我该如何解决这个问题?非常感谢!
【问题讨论】:
input:-webkit-autofill {
color: #999 !important;
}
这对你有用!
【讨论】:
!important。 注意: 是这样的 - color: #999 !important;
!important,只是在有其他方法时会感到懒惰。
试试下面的CSS
input:-webkit-autofill {
-webkit-box-shadow:0 0 0 50px white inset; /* Change the color to your own background color */
-webkit-text-fill-color: #999;
}
input:-webkit-autofill:focus {
-webkit-box-shadow: /*your box-shadow*/,0 0 0 50px white inset;
-webkit-text-fill-color: #999;
}
【讨论】:
试试下面的 CSS:
/* Change Autocomplete styles in Chrome*/
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus
input:-webkit-autofill,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
border: 1px solid green;
-webkit-text-fill-color: green;
-webkit-box-shadow: 0 0 0px 1000px #000 inset;
transition: background-color 5000s ease-in-out 0s;
}
我们可以使用-webkit-autofill 伪选择器来定位这些字段并根据我们认为合适的方式设置它们的样式。
【讨论】: