Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore Webkit's CSS outline on input field

Tags:

css

I want to restore the default CSS outline setting on some form fields but I want it restored to the default Webkit or browser specific style.

The page I'm working with has outline: none applied on all elements, and I just want to revert to the default setting on a few ones. Any ideas?

like image 632
Mario Estrada Avatar asked Jul 06 '11 19:07

Mario Estrada


People also ask

How do I get rid of default input focus border?

border:0; outline:none; box-shadow:none; This should do the trick.

How do you remove an outline in CSS?

Using the CSS rule :focus { outline: none; } to remove an outline on an object causes the link or control to be focusable, but removes any visible indication of focus for keyboard users. Methods to remove it such as onfocus="blur()" result in keyboard users being unable to interact with the link or control.


3 Answers

The answer to your actual question (straight from WebKit's default html.css styles) is this:

:focus {
    outline: auto 5px -webkit-focus-ring-color;
}

The value of -webkit-focus-ring-color is determined on each platform separately (if you're super keen, you can look for WebCore::systemFocusRingColor). In practice, the values vary by platform.

In Safari v6 and Chrome v20 on OS X Lion, the actual value is:

outline: rgb(94, 158, 215) auto 5px;

…and in Chrome v20 on Windows and Chromium v18 on Linux, the value I got was:

outline: rgb(229, 151, 0) auto 5px;

As described in this great StackOverflow answer, you can run this jsFiddle to calculate the outline colour on your own machine.

like image 51
Kit Grose Avatar answered Oct 11 '22 15:10

Kit Grose


Instead of resetting with outline: none, reset with outline-width: 0. This prevents the browser from clearing the styles and when you reapply a width the style will still be there.

input:focus {
  outline-width: 0;
}

input.nostyle:focus {
  outline-width: 5px;
}

http://jsfiddle.net/VT4Hb/

like image 23
methodofaction Avatar answered Oct 11 '22 17:10

methodofaction


use a class on the fields you want without an outline.

.nool { outline: none; }
like image 4
OneOfOne Avatar answered Oct 11 '22 17:10

OneOfOne