While using Google GMail today, I noticed that they put a blue highlighting around the text input boxes when they have input focus. It’s a nice touch that makes it just a bit easier for users to identify which field their typing in. (Safari users, of course, get this on all web sites out of the box.)
Getting this to work on your web site is a simple matter of applying some CSS styles. The trick is to give your normal inputs fields a 1px border and a 1px margin; then, when they have focus, give them a 2px border (with a different color if you so choose) and no margin. This will ensure the dimensions of the element don’t change when the border width changes.
The following CSS provides an example of styling text boxes (both text and password inputs, and multi-line text boxes) and select lists (single and multi-line) with an alternate outline when holding the input focus.
input[type=text], input[type=password], textarea, select { border-top: solid 1px #8e8e8e; border-right: solid 1px #d1d1d1; border-left: solid 1px #d1d1d1; border-bottom: solid 1px #e4e4e4; margin: 1px; padding: 2px; } input[type=text]:focus, input[type=password]:focus, textarea:focus, select:focus { border-color: #4488cc; border-style: solid; border-width: 2px; margin: 0; }
Like many good web tricks, this’ll look great in Firefox but won’t do anything in Internet Explorer. That’s because IE (through version 7) doesn’t support attribute selectors (as in [type=text]
) or the :focus
selector. To get things to work in IE, we need to rely on a little more CSS and some JavaScript.