使用css的文本输入控件不会失去“焦点”风格
我有一个标准输入文本框,我使用 css 和伪类元素悬停和焦点对其进行样式设置。我使用的CSS非常简单:
.riTextBox:hover,
.riTextBox:focus
{
border: solid 1px #F1C15F;
}
.riTextBox
{
border: solid 1px #7394BE;
border-radius: 3.5px;
}
一切都工作得很好,除非文本框中有文本并且用鼠标选择,并且当您选择文本时,您离开了文本框的边界(鼠标按钮仍然按下) ,然后将鼠标移至文本框外的某处。您会注意到文本框边框仍然突出显示,就好像它从未失去焦点一样。
看起来文本框的onselect事件与onblur冲突,但我不确定。请参阅此处重现此令人沮丧的问题:
感谢您可以提供的任何帮助!
I have a standard input textbox that I've styled using css and psuedo-class elements Hover and Focus. The css I am using is pretty simplistic:
.riTextBox:hover,
.riTextBox:focus
{
border: solid 1px #F1C15F;
}
.riTextBox
{
border: solid 1px #7394BE;
border-radius: 3.5px;
}
All is working great except when the textbox has text in it and is selected with the mouse, and as you are selecting the text you leave the bounds of the textbox (with the mouse button still down), and then mouse up somewhere outside the textbox. You will notice that the textbox border is still highlighted as if it never lost focus.
It seems that the onselect event of the textbox is conflicting with onblur, but I'm not sure. See here to reproduce this frustrating issue:
Thanks for any help you can provide!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个答案有点晚了,但它适用于你的问题。只需删除与悬停事件耦合的焦点事件即可。您原来的悬停边框仍将保持焦点(当用户单击该框时),但是当用户将鼠标移开时,悬停样式将消失,即使鼠标按钮仍然按下也是如此。
This answer is a little late, but it works for your problem. Simply remove the focus event that is coupled with the hover event. Your original hover border will still remain on focus (when user clicks the box), but when the user moves the mouse away, the hover styling will disappear, even when the mouse button is still down.