22

There is border around button and link when click.

enter image description here

enter image description here

How can I remove it?

halfer
  • 19,824
  • 17
  • 99
  • 186
Mo.
  • 26,306
  • 36
  • 159
  • 225
  • 5
    That is the focus marker. It tells people who aren't using a mouse/trackball/etc to navigate around where they are in a document. Don't remove it unless you replace it with something more obvious. – Quentin Aug 17 '12 at 14:17
  • It helps if you tell us what you've tried so far, and why it didn't work. That way we can help you a lot better/faster! – Jeroen Aug 17 '12 at 14:18

13 Answers13

48

You can preset it like that :

:focus{
    outline:0; /*removes the dotted border*/
}

But remember (for accessibility reasons) to set the style "later" in your CSS file to something more visible. For example :

a:focus, a:active{
    color:#ff5500; /*different color than regular*/
}
input[type=submit]:focus, input[type=submit]:active{
    background-color:#444; /*different color than regular*/
}
darma
  • 4,687
  • 1
  • 24
  • 25
  • 1
    Are you **sure** that works? I've made a simple demo and the focus ring still appears. – Chris Aug 17 '12 at 15:24
  • 2
    Yes it *does* work, see demo here : http://jsfiddle.net/dLVyK/7/ May i know why the downvote? This solution is perfectly fine. – darma Aug 17 '12 at 15:50
  • 1
    Sorry, I really am sorry -- I had defined a wrong `DOCTYPE`, and thus the rule wasn't working. Can you please edit your answer so that I can change my vote? I apologize again. – Chris Aug 17 '12 at 16:01
  • 2
    @Abody97 - yes that would be nice since i only helped you. you shouldn't downvote without a reason.. – darma Aug 17 '12 at 16:04
14

Try this one

a:hover, a:active, a:focus {
  outline: 0;
 }
Mahadeva Prasad
  • 709
  • 8
  • 19
6

It's ugly, but so are most IE fixes.

a:focus, *:focus {
    noFocusLine: expression(this.onFocus=this.blur());
}
Karl Laurentius Roos
  • 4,360
  • 1
  • 33
  • 42
6

To start with, I can see one of your tags is IE7-bug, while this is actually more like a feature. The purpose of having this dotted outline is for users to be able to navigate between various controls using their mousewheel or the tab key.

In any case, to define the style of an element when it's "focused" use the CSS :focus selector. The property that styles this outline is, trivially, outline; outline: 0 will prevent the focus outline from appearing.

Note: You might want to apply that rule only on your button, and not on all elements, because some users might be used to seeing something to indicate focus, which makes it easier to navigate using the methods mentioned above.

Hope that helped in any manner.

Chris
  • 26,544
  • 5
  • 58
  • 71
5

CSS outline is not supported in IE7. That "browser" requires the following CSS expression:

a {
    _noFocusLine: expression(this.hideFocus=true); 
}

It works also in newer versions.

Vojta Jemelka
  • 136
  • 1
  • 6
3

This would do the trick

a {
   outline:0;
}
Conner
  • 30,144
  • 8
  • 52
  • 73
pwavg
  • 284
  • 3
  • 15
3

This will also work

    a 
    {
        outline-style:none;
    }
PravinS
  • 2,640
  • 3
  • 21
  • 25
3

a:link{ outline-style: none; }`

maindola
  • 53
  • 5
  • 1
    Please don't simply post the code. Give some explanation or information or usage about your code. For example, see [this answer](http://stackoverflow.com/a/16893057/756941). – Nazik Jan 07 '14 at 10:43
2

Try setting the outline property:

a {
   outline: 0;
}
William
  • 413
  • 9
  • 21
2

Try

a {
     outline: none;
}

Always try to use css reset.This will help you to solve the problem like this.I use eric mayer css reset tool.

NewUser
  • 12,713
  • 39
  • 142
  • 236
2

Apply this rule to the input

input { outline : none ; }
Ahmad Alfy
  • 13,107
  • 6
  • 65
  • 99
Andrew
  • 221
  • 3
  • 3
0

This is all around code to remove outerline and put in your your CSS under the desired class name (className in IE). Example for <a> tags

a{
    _noFocusLine:expression(this.hideFocus=true);
    outline-style:none;
    outline:0;
}

Example for all tags in your html page!

*{
    _noFocusLine:expression(this.hideFocus=true);
    outline-style:none;
    outline:0;
}

Example for a tag with class myClassName in your html page!

.myClassName{
    _noFocusLine:expression(this.hideFocus=true);
    outline-style:none;
    outline:0;
}

Example for a tag with id myidName in your html page!

#myidName{
    _noFocusLine:expression(this.hideFocus=true);
    outline-style:none;
    outline:0;
}

Works in major browsers and if not they are so old so the chance of how many people there still are using this old browsers!

Notes: outline:none 0; does also work in newer browsers but not in all. But outline:0; is universal and in those browsers there don´t understand 'none' and you get there's default value, but 0 understand in all browsers there are using outline:.

And you need this for IE7: _noFocusLine:expression(this.hideFocus=true);

or use JavaScript for the rest!

window.document.getElementById("myidName").blur();
window.document.getElementById("myidName").hideFocus=true;
window.document.getElementById("myidName").style.outline=0;

or

Obj=window.document.getElementById("myidName");
Obj.blur();
Obj.hideFocus=true;
Obj.style.outline=0;

or with check if element exist:

if (window.document.getElementById("myidName")){
    Obj=window.document.getElementById("myidName");
    Obj.blur();
    Obj.hideFocus=true;
    Obj.style.outline=0;
}

JavaScript can do the trick for IE6 and IE7 and other CSS can't.

halfer
  • 19,824
  • 17
  • 99
  • 186
-10

You can do it with this code:

   a:focus{
      border: none;
    }
Zendy
  • 1,664
  • 1
  • 17
  • 24
  • 18
    @maanu - Come on, why accept this answer? This isn't even working ! The property you're interested in is outline, not border. Try this in IE : http://jsfiddle.net/dLVyK/10/ = still see the outline = not working. – darma Aug 17 '12 at 18:29
  • @Zendy I appreciated your effort but unofrtunately your soultion doesn't work for me. There is a IE issue when run on windows xp which is only fix with this hack code `noFocusLine: xpression(this.onFocus=this.blur());` that is why accepted right answer – Mo. Aug 15 '14 at 15:50
  • @darma this is what exactely helped me as solution http://www.cssjunction.com/css/remove-dotted-border-in-ie7/ – Mo. Aug 15 '14 at 15:51