首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >键盘聚焦的样式输入字段

键盘聚焦的样式输入字段
EN

Stack Overflow用户
提问于 2021-11-30 10:49:40
回答 1查看 259关注 0票数 0

我试图在输入字段上设置不同的样式,输入字段是通过键盘(而不是鼠标)来聚焦的。

我知道可以通过使用伪类:focus-visible来区分鼠标和键盘对其他元素的关注,但由于等级库的原因,它无法处理输入。

代码语言:javascript
复制
The :focus-visible pseudo-class applies while an element matches the :focus pseudo-class and the UA determines via heuristics that the focus should be made evident on the element.

For example, UAs typically display focus indicators on text fields any time they’re focused, to draw attention to the fact that keyboard input will affect their contents.

On the other hand, UAs typically only display focus indicators on buttons when they were focused by a keyboard interaction (such as tabbing through the document)—because it’s not always immediately obvious where the focus has gone after such an interaction, but is sufficiently self-evident when the button was focused by more obviously-targetted interactions, like clicking on the button with a mouse pointer.

输入字段被鼠标或键盘聚焦时,有什么解决方案来区分样式吗?

EN

回答 1

Stack Overflow用户

发布于 2021-11-30 13:19:48

除了:hover:focus之外,您还可以添加其他样式,如果这对您有效的话。示例如下(https://codepen.io/alekskorovin/pen/OJxJaQB):

代码语言:javascript
复制
input {
  outline: 4px dashed transparent;
}
input:focus-visible {
  outline: 4px dashed darkorange;
}
input:hover:focus-visible {
  outline: 4px dashed darkgreen;
}
input:hover {
  outline: 4px dashed transparent;
}
代码语言:javascript
复制
<input type="text" />

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70168063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档