HTML/CSS - 更改文本字段的属性
当文本字段被选择/活动(即正在输入)时,是否可以更改文本字段的属性。我想简单地更改边框颜色,但我还没有找到实际执行此操作的方法。
我尝试使用 :active 但只有在按下鼠标时才有效(显然我猜)
Is it possible to change the properties of a text field when it's selected/active (i.e. being typed in). I'd like to simply change the border colour but I haven't found a thing about actually doing it.
I tried using :active but that only works when the mouse is pressed (obviously I guess)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您想要的选择器称为
:focus
the selector you want is called
:focus
要在选择/活动输入字段时更改其边框,请使用 :focus
下面的示例:
HTML:
CSS:
说明/详细信息
@ W3Schools CSS:焦点选择器
To change the border of an input field when it's selected/active, use :focus
Example below:
HTML:
CSS:
Explanation / Details
@ W3Schools CSS:focus Selector
您正在寻找 onFocus/onBlur HTML 元素。有了这些,您可以使用 Javascript 来修改颜色/样式标签。
onFocus/onBlur 教程
You are looking for the onFocus/onBlur HTML elements. With these you can use Javascript to modify the colors/style tags.
onFocus/onBlur tutorial