【发布时间】:2019-10-04 16:18:24
【问题描述】:
我正在尝试为输入设置等宽字体,但是当自动填充启动并在自动填充下拉菜单选项之间切换时,文本输入的自动填充状态中的字体系列不会显示为指定的等宽字体,请参阅此代码并将字体系列更改为等宽字体以描述我的问题(我正在使用 Chrome 顺便说一句): Codepen example by CSS tricks
/* Change autocomplete styles in WebKit */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
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;
}
/* PRESENTATIONAL STYLES */
body {
background: #333;
color: #fff;
display: flex;
font-family: monospace;
font-size: 3em;
justify-content: center;
}
form {
padding: 50px 0;
width: 50%;
}
<form>
<div class="form-group">
<label for="exampleInputFirst">First Name</label>
<input type="text" class="form-control input-lg" id="exampleInputFirst">
</div>
<div class="form-group">
<label for="exampleInputLast">Last Name</label>
<input type="text" class="form-control input-lg" id="exampleInputLast">
</div>
<div class="form-group">
<label for="exampleInputEmail">Email Address</label>
<input type="email" class="form-control input-lg" id="exampleInputEmail">
</div>
<button type="submit" class="btn btn-primary btn-lg btn-block">Submit</button>
</form>
【问题讨论】:
-
根据 MDN,“当 元素的值被浏览器自动填充时,:-webkit-autofill CSS 伪类匹配。” - 这仍然适用对于输入字段本身,不是浏览器本身为自动填充功能呈现的自动创建的下拉列表。我很确定您想要的东西是不可能的;这基本上与您为
title属性获得的自动工具提示相同 - 您也不能格式化。 -
我没有尝试更改下拉列表,我在从下拉自动填充列表切换值时遇到文本输入中呈现的文本的问题,字体系列从等宽(由 css 规则指定)到默认值。
-
这与stackoverflow.com/q/56026043/1709587 中描述的问题相同,最终是我报告的security bug 修复的副作用,在提出此问题的前一个月发货。
标签: css