我正在尝试将单拼字体设置为输入,但是当自动填充启动并在自动填充下拉菜单选项之间切换时,该字体家族是文本输入的该自动填充状态。't作为指定的单拼字体出现,请参阅此代码,然后将字体自己更改为Monospace以描绘我的问题(我正在使用Chrome btw(:codepen示例CSS技巧
/* 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
选择器。
它允许您在自动完成元素上的鼠标范围内覆盖默认系统字体(和字体大小(。
这是我的部分答案,希望有帮助:
我在Chrome中遇到了同样的问题,我想在自动填充选项悬停的输入文本区域内更改字体家庭,但这似乎是不会改变的一件事。
从CSS Tricks教程和代码段中所述,我可以尝试更改WebKit中的自动完整样式,我可以更改边框样式,盒子遮阳样式,甚至font-weight
和font-style
。
因为我能够更改悬停在文本输入区域内字体的其他属性,但是 the font-family
,我认为我相信这一点是Chrome的故意或错误。我还注意到CSS技巧上的示例的行为相同:字体家庭是悬停的默认设置,但是选择后切换到LATO。因此,我相信这是Chrome的期望。如果我能找到一些明确的文档,即在这里不允许更改font-family
,我会更加满意,但这是我可以得出的最多。