最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add border to focus css - Stack Overflow

programmeradmin1浏览0评论

I would like to add styling input text box that has a red border when clicked and no border when you click away. I have tried styling input:active but the problem is that when you click away, the red border is still there. Rather than input:active I wan't to manipulate the input:focus to have a red border like so

 textarea:focus, input:focus{
        outline: none; 
        border: 1px solid red;
  }

is there a way to do this?

I would like to add styling input text box that has a red border when clicked and no border when you click away. I have tried styling input:active but the problem is that when you click away, the red border is still there. Rather than input:active I wan't to manipulate the input:focus to have a red border like so

 textarea:focus, input:focus{
        outline: none; 
        border: 1px solid red;
  }

is there a way to do this?

Share Improve this question asked May 23, 2017 at 2:00 MisterCalMisterCal 6222 gold badges7 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

is there a way to do this?

Yes, just do it. Your suggested CSS rules are the right choice as evidenced by the following snippet:

textarea:focus, input:focus {
  outline: none; 
  border: 1px solid red;
}
<textarea></textarea>
<input type="text">

See also How to reset / remove chrome's input highlighting / focus border?

发布评论

评论列表(0)

  1. 暂无评论