我正在尝试将等宽字体设置为输入,但是当自动填充启动并在自动填充下拉菜单选项之间切换时,文本输入的自动填充状态中的字体系列不会显示为指定的等宽字体,请引用此代码并将字体系列更改为等宽字体以描述我的问题(顺便说一句,我正在使用 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>
最佳答案
这里的解决方案是input:-webkit-autofill::first-line
选择器。
它允许您在鼠标悬停在自动完成元素上时覆盖默认系统字体(和字体大小)。
关于文本输入中自动填充的 CSS 字体系列问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56184607/